Home
Register
About
Login
Categories
C#
(13)
VB.NET
(0)
F#
(0)
ASP.NET
(15)
JavaScript
(4)
C++
(0)
C
(0)
Python
(0)
Ruby
(0)
Rails
(0)
J#
(0)
SQL
(0)
VB Script
(0)
HTML
(0)
CSS
(2)
XML
(2)
XSLT
(0)
Unit Testing
(7)
Architecture
(2)
Ajax
(0)
Project Management
(0)
LINQ to SQL
(2)
LINQ
(0)
LINQ to XML
(1)
NHibernate
(0)
Active Record
(0)
Silverlight
(0)
ASP.NET MVC
(0)
Life
(0)
Book Reviews
(0)
WPF
(1)
Visual Studio
(0)
Attaching JavaScript Events With Server Side Binding Code
by azamsharp on 5/22/2008 4:52:51 PM
Recently, I had to send the row index of the GridView row to a JavaScript function. The row index can be accessed using Container.DataItemIndex but I was having trouble with the commas and quotes stuff. So, I just used a server side method to generate a JavaScript method and return to the HTML side. I still think the call to AttachFunction is not a good idea and this should be handled on the client side. Any refactorings?
<ItemTemplate>
<asp:TextBox ID="txtCategoryName" onchange='<%# AttachFunction(Container.DataItemIndex ) %>' runat="server" Text='<%# Eval("CategoryName") %>' />
</ItemTemplate>
protected string AttachFunction(int rowIndex)
{
string function = "saveRowIndex(";
return function + rowIndex + ")";
}
Refactor it!
Please log in to refactor the code!
Login