Run java sctipt code from a LinkButton control
-
Hi, I have a Link button control inside a repeater. What I want to do is when one of the links is clicked to highlight it so that the user could see which link was clicked once. I have the java script code which I used for regular html tags. Now I need to implement it with the linkButton. Does anyone know how to do it? I was trying to use the OnClick method inside the linkButton but obviously it's pointless since it's trying to run the the code in this case c#. Here is the relevant code: <%# SetHeader() %>
***************************************************************** This is Java script: function stuff(el) { var links=document.getElementsById("lb"); for(i=0;i
-
Hi, I have a Link button control inside a repeater. What I want to do is when one of the links is clicked to highlight it so that the user could see which link was clicked once. I have the java script code which I used for regular html tags. Now I need to implement it with the linkButton. Does anyone know how to do it? I was trying to use the OnClick method inside the linkButton but obviously it's pointless since it's trying to run the the code in this case c#. Here is the relevant code: <%# SetHeader() %>
***************************************************************** This is Java script: function stuff(el) { var links=document.getElementsById("lb"); for(i=0;i
Hi there, By default, in ASP.NET 1.x the
OnClick
is the server side event of the LinkButton, so if you want to create an event handler for the client side onclick event of the LinkButton control, you can use the sample code below to add at the server side:LinkButton1.Attributes.Add("onclick", "stuff();");
Because you place the LinkButton inside a repeater control, you can create an event handler for the ItemCreated[^] event of the repeater. In the handler, you can use the
FindControl
method look for the LinkButton in the repeateritem whose ItemType is of the Item or AlternatingItem types. Once you have a reference to the LinkButton control, you can add the onclick client side event handler for the control. Also, by default when you click on the LinkButton, the page will post back to the server. if you don't want that to happen, then you might want to add the codereturn false;
after your client side function. One more thing, with ASP.NET 2.0 you can easily add the client side function for the LinkButton right on the web page thanks to the new feature OnClientClick[^]. -
Hi there, By default, in ASP.NET 1.x the
OnClick
is the server side event of the LinkButton, so if you want to create an event handler for the client side onclick event of the LinkButton control, you can use the sample code below to add at the server side:LinkButton1.Attributes.Add("onclick", "stuff();");
Because you place the LinkButton inside a repeater control, you can create an event handler for the ItemCreated[^] event of the repeater. In the handler, you can use the
FindControl
method look for the LinkButton in the repeateritem whose ItemType is of the Item or AlternatingItem types. Once you have a reference to the LinkButton control, you can add the onclick client side event handler for the control. Also, by default when you click on the LinkButton, the page will post back to the server. if you don't want that to happen, then you might want to add the codereturn false;
after your client side function. One more thing, with ASP.NET 2.0 you can easily add the client side function for the LinkButton right on the web page thanks to the new feature OnClientClick[^]. -
Here is a sample code from my project that changes the innerText of textBox to Uppercase. ctrl is a textbox and ctrlname is the ID value of server side control. Hope it helps..
Dim ctrl As WebControl Dim ctrlname As String = ctrl.ID.ToString() ctrl.Attributes.Add("onblur", "document.getElementById('" + ctrlname & "').value= this.value.toUpperCase();")
--junior coder--