Validation Group

Discussion in 'ASP .Net' started by sck10, Nov 5, 2004.

  1. sck10

    sck10 Guest

    Hello,

    I have a button that is associated with a validation group. When I click
    the button and a validation fails, I still want to code to execute. Can
    this be done? Any help with this would be appreciate.

    Thanks in advance, Sck10

    In my code behind:
    Sub Submit_Click(ByVal Sender As Object, ByVal Args As EventArgs)
    lblRegisterMsg.Text = "<hr />Page.IsValid:" & Page.IsValid.ToString() &
    "<br />"
    End Sub


    Snippet of content page:

    <!-- Test Validation Stuff -->
    <asp:Label id="lblRegisterMsg" runat="server" />
    <asp:ValidationSummary
    ValidationGroup="vgDocUpload"
    id="valSummaryMessage"
    HeaderText="<hr />The following errors were found:"
    runat="server" />


    <tr>
    <td width="100"><div align="right">Submitter:</div></td>
    <td width="500"><div align="left">
    <asp:textbox id="txtSubmitter" Runat="server"/>
    <asp:RequiredFieldValidator ID="rfvSubmitter"
    ValidationGroup="vgDocUpload"
    ControlToValidate="txtSubmitter"
    ErrorMessage="Your name is missing."
    Text="*"
    Runat="server" />
    </div></td>
    </tr>

    <tr>
    <td width="100"><div align="right">Select File:</div></td>
    <td width="500"><div align="left">
    <asp:Button ID="btnUpload"
    ValidationGroup="vgDocUpload"
    Text="Upload"
    OnClick="Submit_Click"
    Runat="server"/>
    </div></td>
    </tr>
    sck10, Nov 5, 2004
    #1
    1. Advertising

  2. Hi Sck10,

    From your description, you're using the Validation Controls on a webform to
    validate some entry fields. And when we push a submit button, the validtion
    will occur which prevent the form be posted back, so you're wondering how
    to make the post back still occur when there is validation error , yes?

    Based on my understanding, this problem is caused by the validation
    controls' clientside validtion which will prevent the form from being
    submit. If you still want the form be posted back( and button's event
    handler be executed), we can choose either of the following means:
    1. Turn off the validation control's EnableClientScript propety (set to
    false) , then the client validation won't take place. But still let the
    submit button as "CauseValidation" = true ( this is the default settting).
    Thus, when we push the submit button, the form will be posted back to
    serverside and validtion is done before button's postback eventhandler
    (after Page_Load).

    2. Set the Submit's CauseValidation to "false" , then the validation won't
    take place automaticaly when we hit the submit button. But we can manually
    call the Page.Validate() in the Page_Load method to manually make the page
    to validating all the controls which is attached with a validtor. Also in
    the Button's Click Event , the Page.IsValid is accessable after the
    validtion.

    And here is a tech article discussing on the underlying detail of ASP.NET's
    validation (client and serverside):

    #ASP.NET Validation in Depth
    http://msdn.microsoft.com/library/en-us/dnaspp/html/aspplusvalid.asp?frame=t
    rue#aspplusvalid_serverside

    Hope also helps. Thanks.

    Regards,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
    Steven Cheng[MSFT], Nov 8, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Akaketwa
    Replies:
    1
    Views:
    4,832
    impaler
    Sep 22, 2006
  2. Replies:
    0
    Views:
    503
  3. christopher taylor
    Replies:
    0
    Views:
    394
    christopher taylor
    Sep 17, 2008
  4. cpld-fpga-asic
    Replies:
    13
    Views:
    1,175
    rickman
    Jul 6, 2009
  5. Dag Sunde
    Replies:
    0
    Views:
    106
    Dag Sunde
    Nov 18, 2005
Loading...

Share This Page