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

Update Command Button ControlID

6 Answers 210 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jagat
Top achievements
Rank 1
Jagat asked on 27 Jun 2011, 05:14 PM
Hello All,

   I have a RadGrid where there will be Update Command and Cancel Command in the edit mode.
  Now  I need to get the Control ID for the Update Command Button. Because, I need to call a Javascript function for that button click.
How do i do that?

Appreciate the Help.
Thanks

6 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 28 Jun 2011, 05:41 AM
HI,

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
   if ((e.Item is GridEditableItem) && (!e.Item.OwnerTableView.IsItemInserted) && (e.Item.IsInEditMode))
    {
        GridEditFormItem editItem = (GridEditFormItem)e.Item;
        LinkButton linkBtn = (LinkButton)editItem.FindControl("UpdateButton");            
        // if button is image button
        //ImageButton imageButton = (ImageButton)editItem.FindControl("UpdateButton"); 
         
             
    }
}

Thanks,
Jayesh Goyani
0
Jagat
Top achievements
Rank 1
answered on 28 Jun 2011, 04:50 PM
Is there a way, that I can use this update button in aspx page, Since I have to use this button in the javascript. like this
<script src="GeoLocation.js"></script>  
    <script>  
         jQuery(window).ready(function(){  
             jQuery("#btn").click(initiate_geolocation);  
         });  
   
         function initiate_geolocation() {  
             navigator.geolocation.getCurrentPosition(handle_geolocation_query);  
         }  
   
        function handle_geolocation_query(position){  
        enableHighAccuracy: true
             alert('Lat: ' + position.coords.latitude + ' ' +  
                   'Lon: ' + position.coords.longitude);  
                  
         }  
     </script>
The highlighted text is the place where I need to use that button.

Thanks

0
Iana Tsolova
Telerik team
answered on 29 Jun 2011, 10:46 AM
Hi Jagat,

You can access the button in the ItemCreated server-side event of the grid and attach the handle for its client click from there:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
    if(e.Item is GridEditFormItem)
    {
        GridEditFormItem editedItem = e.Item as GridEditFormItem;
        LinkButton updateButton = editedItem.FindControl("UpdateButton") as LinkButton;
        updateButton.OnClientClick = "updateButtonClick(this, event)";
        LinkButton cancelButton = editedItem.FindControl("CancelButton") as LinkButton;
        cancelButton.OnClientClick = "cancelButtonClick(this, event)";
    }
}
function updateButtonClick(sender, eventArgs){
    var updateButton = sender;
}
function cancelButtonClick(sender, eventArgs){
    var cancelButton = sender;
}

Regards,
Iana
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Jagat
Top achievements
Rank 1
answered on 30 Jun 2011, 10:19 PM
Thanks for you reply. I have one more question.


Protected Sub RadGrid1_ItemCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemCreated
   
            If TypeOf e.Item Is GridEditFormItem Then
            Dim editedItem As GridEditFormItem = TryCast(e.Item, GridEditFormItem)
            Dim updateButton As ImageButton = TryCast(editedItem.FindControl("UpdateButton"), ImageButton)
            Dim CancelButton As ImageButton = TryCast(editedItem.FindControl("CancelButton"), ImageButton)

            updateButton.OnClientClick = "updateButtonClick(this, event)"
            CancelButton.OnClientClick = "cancelButtonClick(this, event)"

        End If
    End Sub


 above is my ItemCreated event....I have given the Updatebutton and Cancel button as the image buttons.
I have added those 2 functions updatebuttonClick and cancelButtonClick in the aspx page.
Now..  I am getting error ..
Object reference not set to instance of object.
I think the reason behind this is,   I am getting nothing in to the updatebutton and cancelbutton (highlighted). It has nothing.
Those image buttons weren't  not able to find the controls UpdateButton and CancelButton.

Appreciate the Help!
Thanks

0
Jagat
Top achievements
Rank 1
answered on 01 Jul 2011, 03:15 AM
Hello,


  I don't see the error now, Since I used the update command event instead of item Created event.

0
Jayesh Goyani
Top achievements
Rank 2
answered on 01 Jul 2011, 12:19 PM
Hi,

function demoFunction(t1) {
    var t1 =  document.getElementById(t1);
}
LinkButton updateButton = editedItem.FindControl("UpdateButton");
updateButton.Attributes.Add("OnClientClick", "demoFunction('" + updateButton.ClientID +"')");


Thanks,
Jayesh Goyani
Tags
Grid
Asked by
Jagat
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Jagat
Top achievements
Rank 1
Iana Tsolova
Telerik team
Share this question
or