Ajax with field validator

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • goscottie@gmail.com

    Ajax with field validator

    How do I prevent field validator which resides outside of UpdatePanel
    from firing off? The label will update correctly without
    RequiredFieldVa lidator via Ajax. TIA.

    Code below....

    <%@ Page Language="C#" AutoEventWireup ="true"
    CodeBehind="Def ault.aspx.cs" Inherits="WebAp plication1._Def ault" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
    www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title></title>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>
    <asp:ScriptMana ger ID="ScriptManag er1" runat="server">
    </asp:ScriptManag er>

    <asp:TextBox ID="TextBox1" runat="server"> </
    asp:TextBox><as p:RequiredField Validator
    ID="RequiredFie ldValidator1" runat="server"
    ErrorMessage="R equired" ControlToValida te="TextBox1">* </
    asp:RequiredFie ldValidator>
    <asp:UpdatePane l ID="UpdatePanel 1" runat="server">
    <ContentTemplat e>
    <asp:Label ID="Label1" runat="server" Text="Label"></
    asp:Label><br />
    <asp:Button ID="Button1"
    runat="server" Text="Button" onclick="Button 1_Click1" /
    >
    </ContentTemplate >
    </asp:UpdatePanel >

    </div>
    </form>
    </body>
    </html>

    --==========
    Code behind

    protected void Button1_Click1( object sender, EventArgs e)
    {
    Label1.Text = DateTime.Now.To String();
    }
  • Mark Fitzpatrick

    #2
    Re: Ajax with field validator

    You can group the fields via the validationgroup property, although this
    doesn't exactly make sense because if you're trying to validate something
    then it has to be fired with your button that's inside your updatepanel.
    Another possibility is to disable the client-side validation on the
    requiredfieldva lidator. This is good form anyways as you should never really
    perform client-side validation since the validation script can be
    circumvented on the browser.

    Hope this helps,
    Mark Fitzpatrick
    Microsoft MVP - Expression

    <goscottie@gmai l.comwrote in message
    news:e80e27d6-0001-4a03-8eee-8f1fc09d93d4@26 g2000hsk.google groups.com...
    How do I prevent field validator which resides outside of UpdatePanel
    from firing off? The label will update correctly without
    RequiredFieldVa lidator via Ajax. TIA.
    >
    Code below....
    >
    <%@ Page Language="C#" AutoEventWireup ="true"
    CodeBehind="Def ault.aspx.cs" Inherits="WebAp plication1._Def ault" %>
    >
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
    www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
    >
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title></title>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>
    <asp:ScriptMana ger ID="ScriptManag er1" runat="server">
    </asp:ScriptManag er>
    >
    <asp:TextBox ID="TextBox1" runat="server"> </
    asp:TextBox><as p:RequiredField Validator
    ID="RequiredFie ldValidator1" runat="server"
    ErrorMessage="R equired" ControlToValida te="TextBox1">* </
    asp:RequiredFie ldValidator>
    <asp:UpdatePane l ID="UpdatePanel 1" runat="server">
    <ContentTemplat e>
    <asp:Label ID="Label1" runat="server" Text="Label"></
    asp:Label><br />
    <asp:Button ID="Button1"
    runat="server" Text="Button" onclick="Button 1_Click1" /
    >>
    </ContentTemplate >
    </asp:UpdatePanel >
    >
    </div>
    </form>
    </body>
    </html>
    >
    --==========
    Code behind
    >
    protected void Button1_Click1( object sender, EventArgs e)
    {
    Label1.Text = DateTime.Now.To String();
    }

    Comment

    • goscottie@gmail.com

      #3
      Re: Ajax with field validator

      Thanks for replying and sorry for late post.

      I resolved it by, like you said, putting and grouping
      validationgroup . The sample I gave was for simplicity. My original
      requirement was to have two drop down lists and have one fire off and
      populate the second one. For example, first one is country and second
      is the state. So on selectedindexch anged from first one, second will
      populate states based on country selection. Thanks again.

      Comment

      Working...