如何将客户端生成的按钮添加到后面的代码中? [英] How to get the Client side generated button into Code behind?

查看:43
本文介绍了如何将客户端生成的按钮添加到后面的代码中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我已经在客户端创建了按钮.当用户单击按钮时,如何在后面的代码中获取事件?

这是我的JavaScript代码.

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.

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.

推荐答案

您真正需要的是使用Page.GetPostBackReference(Control)方法.这使您可以将控件C1 的服务器端PostBack 事件方法附加到另一个控件C2的客户端事件.

例如,以下代码将按钮的服务器端PostBack 事件附加到Anchor标签的onclick 事件.

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>


这篇关于如何将客户端生成的按钮添加到后面的代码中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆