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

How to access buttonID in Javascript

4 Answers 101 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jeff
Top achievements
Rank 1
Jeff asked on 21 Nov 2008, 10:53 PM

 

 

 

I want to call the click event handler for my iteminsert / itemupdate button from javascript.  How can i reference this button with ID="btnUpdate" as shown below.

I try to use document.getElementById but it is not found. I am guessing this is because the edit form is hidden.
Any help would be appreciated.

Thanks,

 

 

<

EditFormSettings EditFormType="Template">

 

 

 

<FormTemplate>

 

 

 

....
<

asp:Button ID="btnUpdate" TabIndex="3" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'

 

 

 

 

runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'>

 

 

 

</asp:Button>

 

 

 

 

 

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 24 Nov 2008, 09:37 AM
Hello Jeff,

I found the following code library submission on accessing controls inside templates in the grid on client side. Go through it, probably you may find it helpful.
Accessing server controls in a grid template on the client

Thanks
Princy.
0
Jeff
Top achievements
Rank 1
answered on 24 Nov 2008, 04:50 PM
When i put the function 'GetGridServerElement' in the javascript container i get the error message:

The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).
 

function

GetGridServerElement(serverID, tagName)

 

{

 

debugger;

 

 

if (!tagName)

 

tagName =

"*"; //* means all elements

 

 

 

var grid = $get("<%=RadGrid1.ClientID %>");

 

 

debugger;

 

 

var elements = grid.getElementsByTagName(tagName);

 

 

for (var i = 0; i < elements.length; i++)

 

{

 

var element = elements[i];

 

 

if (element.id.indexOf(serverID) >= 0)

 

 

return element;

 

}

}

0
Daniel
Telerik team
answered on 24 Nov 2008, 05:59 PM
Hello Jeff,

Please examine the following articles in order to avoid the depicted error:
RadControls for ASP.NET AJAX Troubleshooting
The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>)

Best Regards,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Jeff
Top achievements
Rank 1
answered on 24 Nov 2008, 06:08 PM
I was able to resolve by placing the javascript container inside a <div runat="server">
Tags
Grid
Asked by
Jeff
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Jeff
Top achievements
Rank 1
Daniel
Telerik team
Share this question
or