Click here to Skip to main content
15,922,145 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi to All, I have created the button in client side. When the user going to click the button how can i get the event in code behind?

Here is my javascript code.

C#
function CreateDeleteButton() {
    debugger;
    var Delete = f('ctl00_cphMaster_tdbtnSave');
    var btnDelete = document.createElement("BUTTON");
    Delete = Delete.appendChild(btnDelete);
    var buttext = document.createTextNode('Delete');
    btnDelete.appendChild(buttext);
    if (btnDelete.onclick = saveEdit) {
        __doPostBack('btnDelete', 'btnDelete_Click');
    }
}
function saveEdit() {
    var ye = confirm("Are You Sure to Delete this Data");
    if (!ye) {
        return false;
    }
}



Please give me the solution to solve my problem.

Thanks to all.
Posted

1 solution

What you really need is to use the Page.GetPostBackReference(Control) method. This allows you to attach the Server side PostBack event method of a control C1 to a client side event of another control C2.

For example, the following piece of code attaches the button's server side PostBack event to the Anchor tag's onclick event.

<a onclick="<%=Page.GetPostBackEventReference(ButtonContol)%>;">Refresh</a>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900