[英]calll click event of a button of aspx page from usercontrol
i have a button in an usercontrol.我在用户控件中有一个按钮。
<asp:Button ID="btnCompare" CssClass="new_btn" runat="server"
Text="Compare" />
i need to call a click event of a button which is in another aspx page on "btnCompare" button click.我需要调用按钮的单击事件,该按钮位于另一个 aspx 页面中的“btnCompare”按钮单击上。
is it possible?可能吗?
Check this link. 检查此链接。 Capture-Button-s-Click-Event-of-User-Control 捕获按钮的用户控制事件
It may help you. 它可能会帮助您。
You can keep that event handler in a js file, which you can use in both the files, or in any file.您可以将该事件处理程序保存在一个 js 文件中,您可以在这两个文件或任何文件中使用该文件。
Yes it is possible.是的,有可能。 You can try achieve this with javascript event handling您可以尝试使用 javascript 事件处理来实现这一点
Edit: From my understanding you are trying to click a button on a page in which the user control also placed.编辑:据我了解,您正试图单击用户控件也放置在其中的页面上的按钮。
Usually what I do is invoke a JavaScript event from user control that actually fires the page button click.通常我所做的是从用户控件调用一个 JavaScript 事件,该事件实际上会触发页面按钮单击。
Example Code In Page.aspx Page.aspx 中的示例代码
function FirePageLevelOkButton(){
var okButton= document.getElementById('<%=btnOk.ClientID %>');
if(okButton){
okButton.click(); // if you have ok button in page you can fire click,
//this will execute codebehind code
}
}
In User Control在用户控制中
<asp:Button ID="btnCompare" CssClass="new_btn" runat="server"
OnClientClick="javascript:FirePageLevelOkButton();" Text="Compare" />
Hope this would help you!希望这对你有帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.