1
我有一個帶有文本框和requiredfieldvalidator以及幾個按鈕的更新面板。RequiredFieldValidator在更新面板中奇怪地工作
在頁面加載中,您會看到一個標籤和一個按鈕。在按鈕按下時,文本框和驗證器顯示(與另一個按鈕一起)。
顯示的基本變化正常。但是,我的驗證器(設置爲動態)顯示其錯誤消息,即使文本框已填充。假設文本框已經填充,按下提交按鈕確實可以工作,但是顯然我的代碼並不完全正確。
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<%
If DoNameUpdate = "" then
%>
<div class="formrow">
<div class="standardlabel">Name: </div>
<div class="fakeformfield"><%=TheName%></div>
<div class="buttonclass"><asp:ImageButton ID="ImageButton1" ImageUrl="/images/changebutton.gif" alt="Change" CssClass="formsub" runat="server" /></div>
</div>
<%
Else
%>
<div class="formrow">
<asp:Label AssociatedControlID="client_name" CssClass="standardlabel" runat="server" Text="Name "></asp:Label><span class="mandatory">*</span>
<asp:TextBox ID="client_name" runat="server" MaxLength="255" CssClass="textboxborder"></asp:TextBox><BR>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="client_name" Display="Dynamic" CssClass="error" ErrorMessage="Required" InitialValue=""></asp:RequiredFieldValidator>
<div class="buttonclass"><asp:ImageButton ID="ImageButton2" ImageUrl="/images/savebutton.gif" alt="Save Changes" CssClass="formsub" runat="server" /></div>
</div>
<%
End if
%>
</ContentTemplate>
</asp:UpdatePanel>
而且代碼隱藏...
Protected Sub ImageButton1_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton1.Click
Dim myReader As IDataReader = CType(SqlDataSource1.Select(DataSourceSelectArguments.Empty), IDataReader)
If myReader.read then
client_name.text = myReader("ClientName")
End if
myReader.close
DoNameUpdate = "val"
End Sub
Protected Sub ImageButton2_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton2.Click
SqlDataSource2a.update()
Dim myReader As IDataReader = CType(SqlDataSource1.Select(DataSourceSelectArguments.Empty), IDataReader)
If myReader.read then
TheName = myReader("ClientName")
End if
myReader.close
DoNameUpdate = ""
End Sub
有什麼建議?
感謝這個;我會試一試,讓我知道如果解決我的問題。 – FrustratedWDotNet