Javascript function Calling from Dynamically creating button click event
-
Hi all, In my application am creating dynamic control as button inside placeholder, but i need to call javascript function for the button click, i dont thing this is possible, if any one knows for this solution plz answer me....
kannak
You are creating dynamic controls using javascript or in server side. I think you can easily use
var but = document.createElement('input');
but.type= "button";
but.onClick = function(){ alert('button clicked');};
document.appendChild(but);to do your job. Hope this helps:suss:
Abhishek Sur My Latest Articles Basics on LINQ and Lambda Expressions
Create .NET Templates -
You are creating dynamic controls using javascript or in server side. I think you can easily use
var but = document.createElement('input');
but.type= "button";
but.onClick = function(){ alert('button clicked');};
document.appendChild(but);to do your job. Hope this helps:suss:
Abhishek Sur My Latest Articles Basics on LINQ and Lambda Expressions
Create .NET TemplatesHi Abhishek, Actually server side button is created dynamically inside placeholder control in a page as like as below, dim btn as new button dim plcHolder as new placeholder PlcHolder.Controls.Add(btn) So button is created sucessfully , but i want to call javascript function when click this button. I think u can understand right now, if u knows Plz answer me, Thank You,
kannak
-
Hi Abhishek, Actually server side button is created dynamically inside placeholder control in a page as like as below, dim btn as new button dim plcHolder as new placeholder PlcHolder.Controls.Add(btn) So button is created sucessfully , but i want to call javascript function when click this button. I think u can understand right now, if u knows Plz answer me, Thank You,
kannak
Hi sekannak, you can add onclick attribute to the button before adding it to the placeholder. dim btn as new button dim pclHolder as new placeholder btn.attributes.add("onclick","alert('hello');") plcHolder.Controls.Add(btn) hope this helps.
Remember, your work is not yours alone. Somewhere, there are some codes written by others amongst us that depends on your work. By failing to see that you are part of their ecosystem, you are bound to break their code. *http://dotnetrandz.blogspot.com*
-
Hi sekannak, you can add onclick attribute to the button before adding it to the placeholder. dim btn as new button dim pclHolder as new placeholder btn.attributes.add("onclick","alert('hello');") plcHolder.Controls.Add(btn) hope this helps.
Remember, your work is not yours alone. Somewhere, there are some codes written by others amongst us that depends on your work. By failing to see that you are part of their ecosystem, you are bound to break their code. *http://dotnetrandz.blogspot.com*
-
no problem. :)
Remember, your work is not yours alone. Somewhere, there are some codes written by others amongst us that depends on your work. By failing to see that you are part of their ecosystem, you are bound to break their code. *http://dotnetrandz.blogspot.com*
-
Hi all, In my application am creating dynamic control as button inside placeholder, but i need to call javascript function for the button click, i dont thing this is possible, if any one knows for this solution plz answer me....
kannak
Can you not just set the onclientclick property on the button you are adding to the placeholder? I.e.
Button btn = new Button();
btn.Text = "Show";
btn.OnClickClick = "alert('Hello');";
placeholder1.Controls.Add(btn);