RadGrid 'Cancel' button in editform pop up mode fires validation

12 posts, 0 answers
  1. Vijay
    Vijay avatar
    8 posts
    Member since:
    Apr 2012

    Posted 30 Apr 2012 Link to this post

    1.I have used required field validators for some input in my edit form of Radgrid. When I click cancel button it fires the validation event first and the Popup form gets closed.

    2.When I click 'Update' with some fields left empty it causes validation.If I click cancel when the validation message exists, nothing is happening. On second click only the Pop up form gets closed. I have used the AutoGenerated EditFormType. Because of this I cant get the button id for 'cancel' and make the CausesValidation false.

    I am not sure why the validation happening for cancel button ? I think because of this Problem 2 might have happened.

    Thanks in Advance.

    Regards,
    VIjay
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 02 May 2012 Link to this post

    Hello Vijay,

    Try the following code to achieve your scenario.
    C#:
    protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
    {
     if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
     {
       LinkButton cancelButton = (LinkButton)e.Item.FindControl("CancelButton");
       cancelButton.CausesValidation = false;
     }
    }

    Thanks,
    Shinu.
  3. Vijay
    Vijay avatar
    8 posts
    Member since:
    Apr 2012

    Posted 02 May 2012 Link to this post

    Hi Shinu,

    Thanks for your support. It worked well.

    Vijay .
  4. Vijay
    Vijay avatar
    8 posts
    Member since:
    Apr 2012

    Posted 04 May 2012 Link to this post

    Hi Shinu,

    Can you please tell me how to find the control for imagebutton in inline mode. I tried this one.
       ImageButtoninsertButton = (ImageButton)e.Item.FindControl("InsertButton");
    But I am getting the value of insertButton as null.

    Thanks

    Vijay.
  5. Vijay
    Vijay avatar
    8 posts
    Member since:
    Apr 2012

    Posted 04 May 2012 Link to this post

    Hi Shinu,

    Can you please tell me how to find the control for imagebutton in inline mode. I tried this one.
       ImageButtoninsertButton = (ImageButton)e.Item.FindControl("InsertButton");
    But I am getting the value of insertButton as null.

    Thanks

    Vijay.
  6. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 04 May 2012 Link to this post

    Hello Vijay,

    I suppose you want to access the default insert button. Here is the sample code.
    C#:
    protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
    {
     if (e.Item is GridEditableItem && e.Item.IsInEditMode)
     {
        LinkButton insertButton = (LinkButton)e.Item.FindControl("PerformInsertButton");
     }
    }

    Thanks,
    Shinu.
  7. Vijay
    Vijay avatar
    8 posts
    Member since:
    Apr 2012

    Posted 05 May 2012 Link to this post

    Hi Shinu,

    I want to know how to get the ID of the button in inPlace edit mode. I want to disable the button after it is clicked once.The button may be update or insert. I have used them as  a image button and not as a linkbutton.

    I am trying to do it in jquery.

    Thanks,
    Vijay.
  8. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 07 May 2012 Link to this post

    Hello Vijay,

    Try the following code to access image button in InPlace edit mode.
    C#:
    protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
    {
      if ((e.Item is GridDataInsertItem && e.Item.IsInEditMode))
      {
        GridDataInsertItem editFormItem = (GridDataInsertItem)e.Item;
        ImageButton img = (ImageButton)editFormItem.FindControl("PerformInsertButton");
        RadGrid1.Controls.Add(new LiteralControl("<script type='text/javascript'>window['btn'] = '" + img.ClientID + "';</script>"));
      }
    }
    JS:
    <script type="text/javascript">
    $(document).ready(function ()
     {
      var btn= document.getElementById(window['btn']);
     });
    </script>

    Thanks,
    Shinu.
  9. Vijay
    Vijay avatar
    8 posts
    Member since:
    Apr 2012

    Posted 07 May 2012 Link to this post

    Hi Shinu,

    Thanks for your code. I got the ID of the image button through

     $('input[type=image]').click(function() {
                        var id = $(this).attr('id');
                        if ($(this).attr('name').indexOf("PerformInsertButton") > 0 || $(this).attr('name').indexOf("UpdateButton") > 0) {
                            $('#' + id + '').attr("disabled", true);
                        }
                    }); in document.ready function

    But when this happens the submit event of the image button is not firing.
    I even tried to __doPostBack(id,''); I am getting postBack event but not the click event of the button.I have done the same thing for the pushbutton and got succeeded in the editform PopupMode.

    Thanks
    Vijay.
  10. Vasil
    Admin
    Vasil avatar
    1640 posts

    Posted 09 May 2012 Link to this post

    Hello,

    Try to attach the onclick attribute for the image button in it's declaration(in your case set it dynamically in the code behind) instead of using the jQuery.
    One more thing that I see is that you are adding "disabled" attribute to the button. Is not supposed in this case the button to not make postback?

    Kind regards,
    Vasil
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  11. Vijay
    Vijay avatar
    8 posts
    Member since:
    Apr 2012

    Posted 10 May 2012 Link to this post

    Hi Vasil,

    Let me explain the issue clearly. I am preventing the user from double clicking the insert/update button in pop up mode as well as in Inplace mode. In pop up mode I am using the push button and in Inplace mode I am using image button.


    I am using the below pageLoad function in  js. In popup mode after I clicked the push button the the button gets disables and also the update event is fired.

    function pageLoad(sender, args) {
                    $('input[type=button]').click(function() {
                    alert('hi');
                        var id = $(this).attr('id');
                        if ($(this).attr('value') == "Cancel") {
                            return false;
                        }
                        else {
                            $('#' + id + '').attr("disabled", true);
                        }
                    });

      $('input[type=image]').click(function() {
                        var id = $(this).attr('id');
                        if ((this).attr('name').indexOf("PerformInsertButton") > 0 || $(this).attr('name').indexOf("UpdateButton") > 0) {
                            $('#' + id + '').attr('disabled', true);
                        }
                        else {
                            $('#' + id + '').attr('disabled', false);
                        }
                    });

                }

    But in case of Inplace mode the button gets disabled and no update/insert event  fires.It is strange for me how the same function behaving differently for the image and push buttons.

    I even tried disabling the image button in update event by

     protected void ICGGrid_UpdateCommand(object sender, GridCommandEventArgs e)
    {
    var editFormItem = (GridDataItem)e.Item;
                    var img = (ImageButton)editFormItem.FindControl("UpdateButton");
                    img.Enabled = false;
    // my code
    }
    But still the problem exists.Can you give me suggestion for this?





  12. Vasil
    Admin
    Vasil avatar
    1640 posts

    Posted 14 May 2012 Link to this post

    Hello Vijay,

    I tried this approach:
    <asp:ImageButton runat="server" ID="ImageButton2" OnClientClick="this.setAttribute('disabled', true);" />
    <asp:Button runat="server" ID="Button2" OnClientClick="this.setAttribute('disabled', true);" />
    And it is working correctly for both buttons. You may try using such approach in the code behind, and to add the click logic there, instead on the Client pageLoad event.

    Kind regards,
    Vasil
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top