This is a migrated thread and some comments may be shown as answers.

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

11 Answers 383 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Vijay
Top achievements
Rank 1
Vijay asked on 30 Apr 2012, 04:06 PM
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

11 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 02 May 2012, 08:45 AM
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.
0
Vijay
Top achievements
Rank 1
answered on 03 May 2012, 04:47 AM
Hi Shinu,

Thanks for your support. It worked well.

Vijay .
0
Vijay
Top achievements
Rank 1
answered on 04 May 2012, 10:28 AM
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.
0
Vijay
Top achievements
Rank 1
answered on 04 May 2012, 10:30 AM
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.
0
Shinu
Top achievements
Rank 2
answered on 04 May 2012, 11:29 AM
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.
0
Vijay
Top achievements
Rank 1
answered on 05 May 2012, 08:16 AM
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.
0
Shinu
Top achievements
Rank 2
answered on 07 May 2012, 10:02 AM
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.
0
Vijay
Top achievements
Rank 1
answered on 07 May 2012, 11:04 AM
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.
0
Vasil
Telerik team
answered on 09 May 2012, 02:46 PM
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.
0
Vijay
Top achievements
Rank 1
answered on 10 May 2012, 05:35 AM
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?





0
Vasil
Telerik team
answered on 14 May 2012, 07:48 AM
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.
Tags
General Discussions
Asked by
Vijay
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Vijay
Top achievements
Rank 1
Vasil
Telerik team
Share this question
or