Solved

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

Posted on 2010-11-15
10
989 Views
Last Modified: 2012-08-13
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."
0
Comment
Question by:HLRosenberger
10 Comments
 
LVL 5

Expert Comment

by:vivekpv10
ID: 34142530
make that button click event as publick...then call like this..
  btnSave_Click(sender, e);
0
 
LVL 10

Expert Comment

by:hosneylk
ID: 34142534

document.getElementById('btnId').click();

Open in new window

0
 
LVL 3

Expert Comment

by:mahmoodvcs
ID: 34143801
from the child window (triggering click on parent window):

opener.document.getElementById('btnId').click();

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

var wnd = window.open('url');

then use:

wnd.document.getElementById('btnId').click();
0
 
LVL 1

Author Comment

by:HLRosenberger
ID: 34148649
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?
0
 
LVL 10

Expert Comment

by:hosneylk
ID: 34150508

window.opener.document.getElementById('btnId').click()



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

Open in new window

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Author Comment

by:HLRosenberger
ID: 34198425
I tried this.  it does not seem to work.  The button ID.  How does the codue know which page the button is on?  
0
 
LVL 10

Expert Comment

by:hosneylk
ID: 34202016
well when you say window.opener it means the parent window. try adding a function in the parent and calling that.

e.g.
parent page:

function testCall() {

   alert('comes here');

}



popup page:

window.opener.testCall();

Open in new window

0
 
LVL 1

Author Comment

by:HLRosenberger
ID: 34210132
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?
0
 
LVL 10

Accepted Solution

by:
hosneylk earned 500 total points
ID: 34210148
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 asp.net. so it's better to always use this syntax when using server conrols in javascript.
0
 
LVL 1

Author Closing Comment

by:HLRosenberger
ID: 34210165
Thanks for the explanation!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now