Update button in datagrid causing validation elsewhere on page

Discussion in 'ASP .Net' started by =?Utf-8?B?RGF2aWQgQ29sbGl2ZXI=?=, May 24, 2005.

  1. Hi all,

    I am having a slight problem that hopefully, someone can help me fix.

    I have a form on a page. Many items on the form have validation controls
    attached.
    Also on this form are linkbuttons which must not cause validation. I have
    found a setting "causeValidation" to disable the validation.

    Also on the page, I have a datagrid that I will edit lines on. I can click
    edit and cancel without enforced validation, however, if I click Update, the
    validation comes up.

    I have tried to put a causesValidation="false" in the linkbutton column on
    the datagrid but to no avail.

    When I hover over the Update link, I have...
    javascript:{if {typeod(Page_ClientValidate) != 'function' ||
    Page_ClientValidate()) __doPostback...

    in the status bar.

    How can I override the Update link to prevent the validation from happening?

    Also, if I was to limit just the Update to the datagrid text boxes, how
    would I validate those?

    A third Q... when in edit mode of the datagrid, how can I use a DropDownList
    instead of a text box?

    Thanks.

    Best regards,
    Dave Colliver.
    http://www.AshfieldFOCUS.com
    ~~
    http://www.FOCUSPortals.com - Portal franchises available
     
    =?Utf-8?B?RGF2aWQgQ29sbGl2ZXI=?=, May 24, 2005
    #1
    1. Advertising

  2. =?Utf-8?B?RGF2aWQgQ29sbGl2ZXI=?=

    Peter Blum Guest

    Hi David,

    ASP.NET 2.0 will solve it with the introduction of "validation groups". It
    allows you to assign a group name to the submit control and the validators
    it fires. My Professional Validation And More product
    (http://www.peterblum.com/vam/home.aspx) supports validation groups (its
    actually more powerful than the ASP.NET 2.0 version although they look very
    similar.)

    In ASP.NET 1.x, the normal way to get the same behavior is to turn off
    client-side validation on the submit button. This would work for your
    linkbutton:
    - Set CausesValidation=false
    - In the Click post back event method, call each validator's Validate()
    method that applies to this button. Then test IsValid is true on all of the
    same validators. Proceed if all are true.

    This is harder with a DataGrid because the Update button's CausesValidation
    property is hidden from you and is always true.

    I encourage you to download the trial version of Professional Validation And
    More to explore how it can help you. Its a much bigger system than just a
    fix to this problem. It has 45 controls and many new ideas for validation
    including client-side support of validation on many more browsers like
    FireFox and Safari.

    --- Peter Blum
    www.PeterBlum.com
    Email:
    Creator of "Professional Validation And More" at
    http://www.peterblum.com/vam/home.aspx

    "David Colliver" <> wrote in message
    news:...
    > Hi all,
    >
    > I am having a slight problem that hopefully, someone can help me fix.
    >
    > I have a form on a page. Many items on the form have validation controls
    > attached.
    > Also on this form are linkbuttons which must not cause validation. I have
    > found a setting "causeValidation" to disable the validation.
    >
    > Also on the page, I have a datagrid that I will edit lines on. I can click
    > edit and cancel without enforced validation, however, if I click Update,
    > the
    > validation comes up.
    >
    > I have tried to put a causesValidation="false" in the linkbutton column on
    > the datagrid but to no avail.
    >
    > When I hover over the Update link, I have...
    > javascript:{if {typeod(Page_ClientValidate) != 'function' ||
    > Page_ClientValidate()) __doPostback...
    >
    > in the status bar.
    >
    > How can I override the Update link to prevent the validation from
    > happening?
    >
    > Also, if I was to limit just the Update to the datagrid text boxes, how
    > would I validate those?
    >
    > A third Q... when in edit mode of the datagrid, how can I use a
    > DropDownList
    > instead of a text box?
    >
    > Thanks.
    >
    > Best regards,
    > Dave Colliver.
    > http://www.AshfieldFOCUS.com
    > ~~
    > http://www.FOCUSPortals.com - Portal franchises available
     
    Peter Blum, May 24, 2005
    #2
    1. Advertising

  3. Hi David,

    As you mention, causeValidation can disable the validation. You can set
    Update Button's causeValidation in datagrid_EditCommand event:


    datagrid.EditItemIndex = e.Item.ItemIndex;
    datagrid.DataBind();

    LinkButton updateBtn =
    (LinkButton)datagrid.Items[e.Item.ItemIndex].Controls[0];
    updateBtn.CausesValidation = false;

    HTH

    Elton Wang


    "David Colliver" wrote:

    > Hi all,
    >
    > I am having a slight problem that hopefully, someone can help me fix.
    >
    > I have a form on a page. Many items on the form have validation controls
    > attached.
    > Also on this form are linkbuttons which must not cause validation. I have
    > found a setting "causeValidation" to disable the validation.
    >
    > Also on the page, I have a datagrid that I will edit lines on. I can click
    > edit and cancel without enforced validation, however, if I click Update, the
    > validation comes up.
    >
    > I have tried to put a causesValidation="false" in the linkbutton column on
    > the datagrid but to no avail.
    >
    > When I hover over the Update link, I have...
    > javascript:{if {typeod(Page_ClientValidate) != 'function' ||
    > Page_ClientValidate()) __doPostback...
    >
    > in the status bar.
    >
    > How can I override the Update link to prevent the validation from happening?
    >
    > Also, if I was to limit just the Update to the datagrid text boxes, how
    > would I validate those?
    >
    > A third Q... when in edit mode of the datagrid, how can I use a DropDownList
    > instead of a text box?
    >
    > Thanks.
    >
    > Best regards,
    > Dave Colliver.
    > http://www.AshfieldFOCUS.com
    > ~~
    > http://www.FOCUSPortals.com - Portal franchises available
     
    =?Utf-8?B?RWx0b24gVw==?=, May 24, 2005
    #3
  4. Hi Elton,

    Thank you.

    However, I am having a problem...

    I have exactly the code you have suggested (with object names changed as
    neccessary) but I am getting...

    System.ArgumentOutOfRangeException: Index was out of range. Must be
    non-negative and less than the size of the collection. Parameter name: index

    My code...

    private void SecondaryEdEducationDataGrid_EditCommand(object source,
    System.Web.UI.WebControls.DataGridCommandEventArgs e)
    {
    SecondaryEdEducationDataGrid.EditItemIndex = e.Item.ItemIndex;
    SecondaryEdEducationDataGrid.DataBind();
    Trace.Warn("ItemIndex", e.Item.ItemIndex.ToString());
    LinkButton updateBtn =
    (LinkButton)SecondaryEdEducationDataGrid.Items[e.Item.ItemIndex].Controls[0];
    updateBtn.CausesValidation = false;
    }

    The line that is being pointed to is the "LinkButton updateBtn" line.

    I understand what you are pointing me at, and it was an area that I had not
    considered.

    Thanks.
    Regards,
    Dave Colliver.
    http://www.DerbyFOCUS.com
    ~~
    http://www.FOCUSPortals.com - Portal franchises available


    "Elton W" wrote:

    > Hi David,
    >
    > As you mention, causeValidation can disable the validation. You can set
    > Update Button's causeValidation in datagrid_EditCommand event:
    >
    >
    > datagrid.EditItemIndex = e.Item.ItemIndex;
    > datagrid.DataBind();
    >
    > LinkButton updateBtn =
    > (LinkButton)datagrid.Items[e.Item.ItemIndex].Controls[0];
    > updateBtn.CausesValidation = false;
    >
    > HTH
    >
    > Elton Wang
    >
    >
    > "David Colliver" wrote:
    >
    > > Hi all,
    > >
    > > I am having a slight problem that hopefully, someone can help me fix.
    > >
    > > I have a form on a page. Many items on the form have validation controls
    > > attached.
    > > Also on this form are linkbuttons which must not cause validation. I have
    > > found a setting "causeValidation" to disable the validation.
    > >
    > > Also on the page, I have a datagrid that I will edit lines on. I can click
    > > edit and cancel without enforced validation, however, if I click Update, the
    > > validation comes up.
    > >
    > > I have tried to put a causesValidation="false" in the linkbutton column on
    > > the datagrid but to no avail.
    > >
    > > When I hover over the Update link, I have...
    > > javascript:{if {typeod(Page_ClientValidate) != 'function' ||
    > > Page_ClientValidate()) __doPostback...
    > >
    > > in the status bar.
    > >
    > > How can I override the Update link to prevent the validation from happening?
    > >
    > > Also, if I was to limit just the Update to the datagrid text boxes, how
    > > would I validate those?
    > >
    > > A third Q... when in edit mode of the datagrid, how can I use a DropDownList
    > > instead of a text box?
    > >
    > > Thanks.
    > >
    > > Best regards,
    > > Dave Colliver.
    > > http://www.AshfieldFOCUS.com
    > > ~~
    > > http://www.FOCUSPortals.com - Portal franchises available
     
    =?Utf-8?B?RGF2aWQgQ29sbGl2ZXI=?=, May 25, 2005
    #4
  5. Sorted now...

    It should be...

    LinkButton updateBtn =
    (LinkButton)datagrid.Items[e.Item.ItemIndex].Controls[0].Controls[0];

    Notice the second .Controls[0] ?

    Regards,
    Dave Colliver.
    http://www.ChesterfieldFOCUS.com
    ~~
    http://www.FOCUSPortals.com - Portal franchises available


    "David Colliver" wrote:

    > Hi Elton,
    >
    > Thank you.
    >
    > However, I am having a problem...
    >
    > I have exactly the code you have suggested (with object names changed as
    > neccessary) but I am getting...
    >
    > System.ArgumentOutOfRangeException: Index was out of range. Must be
    > non-negative and less than the size of the collection. Parameter name: index
    >
    > My code...
    >
    > private void SecondaryEdEducationDataGrid_EditCommand(object source,
    > System.Web.UI.WebControls.DataGridCommandEventArgs e)
    > {
    > SecondaryEdEducationDataGrid.EditItemIndex = e.Item.ItemIndex;
    > SecondaryEdEducationDataGrid.DataBind();
    > Trace.Warn("ItemIndex", e.Item.ItemIndex.ToString());
    > LinkButton updateBtn =
    > (LinkButton)SecondaryEdEducationDataGrid.Items[e.Item.ItemIndex].Controls[0];
    > updateBtn.CausesValidation = false;
    > }
    >
    > The line that is being pointed to is the "LinkButton updateBtn" line.
    >
    > I understand what you are pointing me at, and it was an area that I had not
    > considered.
    >
    > Thanks.
    > Regards,
    > Dave Colliver.
    > http://www.DerbyFOCUS.com
    > ~~
    > http://www.FOCUSPortals.com - Portal franchises available
    >
    >
    > "Elton W" wrote:
    >
    > > Hi David,
    > >
    > > As you mention, causeValidation can disable the validation. You can set
    > > Update Button's causeValidation in datagrid_EditCommand event:
    > >
    > >
    > > datagrid.EditItemIndex = e.Item.ItemIndex;
    > > datagrid.DataBind();
    > >
    > > LinkButton updateBtn =
    > > (LinkButton)datagrid.Items[e.Item.ItemIndex].Controls[0];
    > > updateBtn.CausesValidation = false;
    > >
    > > HTH
    > >
    > > Elton Wang
    > >
    > >
    > > "David Colliver" wrote:
    > >
    > > > Hi all,
    > > >
    > > > I am having a slight problem that hopefully, someone can help me fix.
    > > >
    > > > I have a form on a page. Many items on the form have validation controls
    > > > attached.
    > > > Also on this form are linkbuttons which must not cause validation. I have
    > > > found a setting "causeValidation" to disable the validation.
    > > >
    > > > Also on the page, I have a datagrid that I will edit lines on. I can click
    > > > edit and cancel without enforced validation, however, if I click Update, the
    > > > validation comes up.
    > > >
    > > > I have tried to put a causesValidation="false" in the linkbutton column on
    > > > the datagrid but to no avail.
    > > >
    > > > When I hover over the Update link, I have...
    > > > javascript:{if {typeod(Page_ClientValidate) != 'function' ||
    > > > Page_ClientValidate()) __doPostback...
    > > >
    > > > in the status bar.
    > > >
    > > > How can I override the Update link to prevent the validation from happening?
    > > >
    > > > Also, if I was to limit just the Update to the datagrid text boxes, how
    > > > would I validate those?
    > > >
    > > > A third Q... when in edit mode of the datagrid, how can I use a DropDownList
    > > > instead of a text box?
    > > >
    > > > Thanks.
    > > >
    > > > Best regards,
    > > > Dave Colliver.
    > > > http://www.AshfieldFOCUS.com
    > > > ~~
    > > > http://www.FOCUSPortals.com - Portal franchises available
     
    =?Utf-8?B?RGF2aWQgQ29sbGl2ZXI=?=, May 25, 2005
    #5
    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. John Dalberg
    Replies:
    1
    Views:
    352
    Steven
    Jul 23, 2004
  2. Mr. Magic
    Replies:
    1
    Views:
    451
    Gregory A. Beamer
    Jan 4, 2010
  3. Tina

    DataGrid Buttons causing validation

    Tina, Nov 18, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    2
    Views:
    113
  4. Geoff Murley

    Stop datagrid causing validation

    Geoff Murley, Apr 12, 2005, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    111
    Brock Allen
    Apr 12, 2005
  5. Joe90

    Datagrid Update Button causing unwanted validation

    Joe90, Aug 2, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    161
    Joe90
    Aug 2, 2005
Loading...

Share This Page