0
如果您點擊第一個按鈕,第一個面板出現,第二個面板出現隱藏,如果您點擊第二個按鈕,則顯示一個帶有2個面板的1個更新面板的2頁面控制的asp頁面第二個面板發生了事情。它工作正常,沒有問題。更新小窗口塊阻止執行一些錯誤消息
問題出現在第二個面板中,我有另一個負責打印錯誤消息的更新面板。只檢查輸入長度的消息正常,但涉及查詢數據庫以檢查id有效性的消息未被打印。
我認爲查詢是問題,我試過他們在一個沒有更新面板的分離頁面,他們工作正常。問題在更新面板的某個地方。我真的不明白在哪裏。如果你能幫助我,我將不勝感激。
這是前端代碼(我忽略了一些不起眼的細節):
<asp:Button ID="Button1" runat="server" Text="[Input your Id?]" />
<asp:Button ID="Button2" runat="server" Text="[Aditional info]" />
.....
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
< asp:Panel ID="Panel1" runat="server">
some code here
</asp:Panel>
<asp:Panel ID="Panel2" runat="server">
<b>*ID Number: </b>
<asp:TextBox ID="IdNo" runat="server" ></asp:TextBox><font size='2'>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" class="errorMess" ErrorMessage="Letters are not Allowed!!" ControlToValidate="IdNumb" ValidationExpression="\d+"
runat="server" />
<asp:UpdatePanel ID="UpdatePanel3" runat="server">
<ContentTemplate>
<asp:Label ID="errorEm" class="errorMess" runat="server" Text="Please fill in the required fields"></asp:Label>
<asp:Label ID="errorLenght" class="errorMess" runat="server" Text="Id is too long!!!"></asp:Label>
<asp:Label ID="errorUser" class="errorMess" runat="server" Text="Id is not valid!!!"></asp:Label>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button5" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
<asp:Button ID="Button5" runat="server" Text="Generate" /></td></tr>
</asp:Panel>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
,這是後端VB代碼:
Protected Sub Button5_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button5.Click
If IdNo.Text = "" Then
Panel1.Visible = False
Panel2.Visible = True
errorEm.Visible = True
ElseIf IdNo.Text.Length > 9 Then
Panel1.Visible = False
Panel2.Visible = True
errorLenght.Visible = True
Else
Try 'everything that comes here does not work'
myconn.Open()
Dim stquery As String = "SELECT * from account WHERE user_id= @id"
Dim smd = New MySqlCommand(stquery, myconn)
smd.Parameters.AddWithValue("@id", Convert.ToInt32(IdNo.Text))
Dim myreader = smd.ExecuteReader()
If Not myreader.HasRows Then
Panel1.Visible = False
Panel2.Visible = True
errorUser.Visible = True
myconn.Close()
Return
Else
Panel1.Visible = False
Panel2.Visible = True
myreader.Read()
Dim ErrorMessage As String = "alert('User has been found');"
Page.ClientScript.RegisterStartupScript(Me.GetType(), "ErrorAlert", ErrorMessage, True)
myconn.Close()
End If
myconn.Close()
Catch ex As Exception
Dim ErrorMessage As String = "alert('" & ex.Message.ToString() & "');"
Page.ClientScript.RegisterStartupScript(Me.GetType(), "ErrorAlert", ErrorMessage, True)
myconn.Close()
End Try
End If
End Sub
你知道'RegularExpressionValidator'可以用來驗證輸入的長度,這樣你就不必檢查它的代碼隱藏手動?只需設置ValidationExpression =「^ \ d {5,9} $」'這意味着輸入只能是數字,長度在5到9個字符之間。 – ajakblackgoat 2013-05-03 05:35:52