简体   繁体   中英

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.

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.

Yes it is possible. You can try achieve this with javascript event handling

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.

Example Code In 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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM