Validation Breaks Postback (C#)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • spamguy
    New Member
    • Sep 2007
    • 42

    Validation Breaks Postback (C#)

    Before I added validation features, I had a few controls that made use of postback: for example, click a checkbox to make Panel1 and subcontrols visible.

    I've since added clientside and serverside validation and suddenly postback is broken. Only if 'Submit' is clicked does the form update with changes that should have occured automatically.

    Page_Load() has nothing involving IsPostBack, so I have no idea what else could be breaking it.
  • nateraaaa
    Recognized Expert Contributor
    • May 2007
    • 664

    #2
    Originally posted by spamguy
    Before I added validation features, I had a few controls that made use of postback: for example, click a checkbox to make Panel1 and subcontrols visible.

    I've since added clientside and serverside validation and suddenly postback is broken. Only if 'Submit' is clicked does the form update with changes that should have occured automatically.

    Page_Load() has nothing involving IsPostBack, so I have no idea what else could be breaking it.
    Post the code for your page_load event and your checkChanged event. Maybe seeing the code will give us a better idea of what is going on. (Please surround your code with code tags).

    thanks
    Nathan

    Comment

    • spamguy
      New Member
      • Sep 2007
      • 42

      #3
      Originally posted by nateraaaa
      Post the code for your page_load event and your checkChanged event. Maybe seeing the code will give us a better idea of what is going on. (Please surround your code with code tags).

      thanks
      Nathan
      I normally supply code with my questions, but as I said, I didn't find anything of worth in Page_Load(), so I left it off. But you're welcome to it. As a bonus is a DropDownList also not responding to postback; it should enable a TextBox when 'Other' is chosen:

      [code=cpp]
      protected void Page_Load(objec t sender, EventArgs e)
      {
      // enable/disable secondary contact fields based on checkbox status
      Panel1.Enabled = cbSecondaryCont act.Checked;
      }

      protected void cbSecondaryCont act_CheckedChan ged(object sender, EventArgs e)
      {
      Panel1.Enabled = cbSecondaryCont act.Checked;
      }

      protected void ddlOrganisation _SelectedIndexC hanged(object sender, EventArgs e)
      {
      txtOther.Enable d = ddlOrganisation .SelectedValue == "Other" ? true : false;
      }
      [/code]

      Comment

      • nateraaaa
        Recognized Expert Contributor
        • May 2007
        • 664

        #4
        You have the AutoPostBack property of these controls set to true correct?

        Nathan

        Comment

        • spamguy
          New Member
          • Sep 2007
          • 42

          #5
          Originally posted by nateraaaa
          You have the AutoPostBack property of these controls set to true correct?

          Nathan
          Right. Since these controls were working as expected earlier, AutoPostBack was and still is set to true.

          Comment

          • nateraaaa
            Recognized Expert Contributor
            • May 2007
            • 664

            #6
            Originally posted by spamguy
            Right. Since these controls were working as expected earlier, AutoPostBack was and still is set to true.
            What kind of validation are you doing? Are you using any required field validators or any other .NET validation controls? How are you displaying the validation to the user?

            Nathan

            Comment

            • spamguy
              New Member
              • Sep 2007
              • 42

              #7
              It's a mixture of RequiredFieldVa lidators and RegularExpressi onValidators. Any fields with errors have red asterisks appear beside them; errors are listed in the ValidationSumma ry up top:

              [code=html]
              <form id="form1" method="POST" action="" runat="server">
              <div style="width:10 0%">
              <asp:Validation Summary ID="ValidationS ummary1" CssClass="error Message" runat="server" ForeColor="Blac k" /><br />
              <asp:Panel ID="noHTMLPanel " runat="server" CssClass="error Message" Visible="false" >HTML tags are not permitted in the form submission.</asp:Panel>
              </div>
              <p>
              <label for="txtFirstNa me">First Name: </label>
              <asp:TextBox ID="txtFirstNam e" Width="225px" runat="server"> </asp:TextBox>
              <asp:RequiredFi eldValidator ID="vdFirstName " runat="server" ControlToValida te="txtFirstNam e" ErrorMessage="& quot;First Name&quot; is required." Text="*" />
              <br />

              <label for="txtLastNam e">Last Name: </label>
              <asp:TextBox ID="txtLastName " Width="225px" runat="server"> </asp:TextBox>
              <asp:RequiredFi eldValidator ID="vdLastName " runat="server" ControlToValida te="txtLastName " ErrorMessage="& quot;Last Name&quot; is required." Text="*" />
              <br />

              <label for="txtEmail"> Email Address: </label>
              <asp:TextBox ID="txtEmail" Width="225px" runat="server"> </asp:TextBox>
              <asp:RequiredFi eldValidator ID="vdEmail" runat="server" ControlToValida te="txtEmail" ErrorMessage="& quot;Email&quot ; is required." Text="*" />
              <asp:RegularExp ressionValidato r ID="vdREEmail" runat="server" ControlToValida te="txtEmail" Text="*" ErrorMessage="T he email address is not in a valid format." ValidationExpre ssion="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" />
              <br />
              </p>

              <!-- and so on... -->
              [/code]

              Comment

              Working...