2
我新的ASP.NET和AJAX,所以我可能會處理事情完全走錯了路,ASP.Net VB - 傳遞更新的UpdatePanel值回另一回調函數
這是目前所有的只是測試,我有一個帶有onclick函數的updatepanel來訪問數據庫和更新值。我正在嘗試通過按鏈接按鈕來更新頁面上的客戶端ID。這適用於第一次點擊,但後續點擊顯然仍在讀取服務器端數據,而不是更新後的客戶端數據,現在我需要能夠將客戶端ID的更新值恢復到我的linkbutton點擊功能。
ASPX代碼
<form id="form1" runat="server">
<asp:toolkitscriptmanager ID="ToolkitScriptManager1" runat="server">
</asp:toolkitscriptmanager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="LinkButton1" EventName="click" />
</Triggers>
<ContentTemplate>
<div class="topbox">
<h3>Client</h3>
<div style="float:left">
<p>
<asp:Label ID="Label1" runat="server" Text="ClientID" Width="150px"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</p>
<asp:LinkButton ID="LinkButton1" runat="server">next --></asp:LinkButton>
</ContentTemplate>
</asp:UpdatePanel>
</form>
ASPX.VB代碼
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Open_database(1)
End Sub
Public Sub Open_database(e)
Dim SQLConn As New SqlConnection()
'The SQL Connection
Dim SQLCmd As New SqlCommand()
'The SQL Command
Dim SQLdr As SqlDataReader
'The Local Data Store
SQLConn.ConnectionString = xxxx
'Set the Connection String
SQLConn.Open()
'Open the connection
SQLCmd.Connection = SQLConn
'Sets the Connection to use with the SQL Command
SQLCmd.CommandText = "Select * from Client where clientid='" & e & "'"
'Sets the SQL String
SQLdr = SQLCmd.ExecuteReader
'Gets Data
While SQLdr.Read()
TextBox1.Text = (SQLdr("ClientID"))
End While
' Do While SQLdr.NextResult()
'Move to the Next Record
SQLdr.Close()
'Close the SQLDataReader
SQLConn.Close()
'Close the connection
End Sub
Protected Sub LinkButton1_Click(sender As Object, e As EventArgs) Handles LinkButton1.Click
Dim x = TextBox1.Text + 1
Open_database(x)
End Sub
任何幫助,將不勝感激,
twun
,所以我想通了這一點使用; '私人共享globalvar作爲Integer' 和改變了我的點擊事件, '保護小組LinkButton1_Click(發送者爲對象,例如作爲EventArgs的)把手LinkButton1.Click globalvar = globalvar + 1 Open_database(globalvar) 完Sub' – twun