Monday, March 26, 2012

multiview requiredfieldvalidator and updatepanel error - entire simple code posted

Problem is when I click on linkbutton2 then click on the button on that page is get the null error. It's being caused because it's looking for the validator from view1.

I know I can say causesvalidation=false, but I will have tons of items in view2 and don't want to do it that way.

I want to say RequiredFieldValidator1.enabled=false for the view2 section. But where do I call this? Also when they go back to view1 it should say this RequiredFieldValidator1.enabled=true.

code behind:

Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
MultiView1.ActiveViewIndex = 0
End Sub

Protected Sub LinkButton2_Click(ByVal sender As Object, ByVal e As System.EventArgs)
MultiView1.ActiveViewIndex = 1
End Sub

source:

<form id="form1" runat="server">
<atlas:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true" />
<atlas:UpdatePanel runat="server" ID="calendarupdatepanel">

<ContentTemplate>

<asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click" CausesValidation="false">Search</asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" OnClick="LinkButton2_Click" CausesValidation="false">Results</asp:LinkButton>
<br />
<asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0">
<asp:View ID="view1" runat="server">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1"
ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>
</asp:View>
<asp:View ID="view2" runat="server">
<asp:Button ID="Button1" runat="server" Text="Button" />
</asp:View>
</asp:MultiView>
<asp:Label id="ActiveViewLabel"
BorderStyle=None
Font-Size=Small
BackColor="#ffff66"
runat="Server" Text="" >
</asp:Label>
</ContentTemplate>
</atlas:UpdatePanel>

</form

fixed this one - never mind

No comments:

Post a Comment