Improve company productivity with a Business Account.Sign Up

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1003
  • Last Modified:

Call the click event of a ASP.NET button from another form

I want to Call the click event of a ASP.NET button from another form.  How can I do this?  Can I use JavaScript?

This was suggested to me.  Does this make sense?

"Probably the simplest way of triggering the AJAX refresh across windows is to put a refresh button on the calling page, hide it with Javascript, and then call its click() method from the other page by using that same opener property to access the first page. You might need the document.getElementById('refreshButtonName'); function to find the refresh button."
1 Solution
make that button click event as publick...then call like this..
  btnSave_Click(sender, e);


Open in new window

from the child window (triggering click on parent window):


from the parent window, if you have opened a window like this:

var wnd ='url');

then use:

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

HLRosenbergerAuthor Commented:
The child window is a popup and I display it using window.showModalDialog.

I tried opener.document.getElementById('btnId').click()  and  wnd.document.getElementById('btnId').click()   and neither seems to work, unless I am doing something wrong.   There is an accept button on the popup that does self.close().   When accept is click, this is where I want to trigger a refresh button click on the page from which i opened the popup?

Question:  How does it know to look for the button on the parent page and not on the popup?


should work when called from the popup before calling self.close

Open in new window

HLRosenbergerAuthor Commented:
I tried this.  it does not seem to work.  The button ID.  How does the codue know which page the button is on?  
well when you say window.opener it means the parent window. try adding a function in the parent and calling that.

parent page:
function testCall() {
   alert('comes here');

popup page:

Open in new window

HLRosenbergerAuthor Commented:
I found my problem - I need to reference the ASP button like this:

var RefreshButton= window.document.getElementById("<%= Unidentified_DocumentsRefreshButton.ClientID %>");

What's the deal with the  <%= %> syntax?  What does that tell the JavaScript interpreter?  Do you know if I always need this syntax?
its not javascript syntax. this happens when the server ID of Unidentified_DocumentsRefreshButton is not the same as the generated client ID. this might be because it's within a control. you can check this by looking at the source of the page in the browser.

what the ode above does is that it returns the generated clientid of the button. this is done when the page is generated by so it's better to always use this syntax when using server conrols in javascript.
HLRosenbergerAuthor Commented:
Thanks for the explanation!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now