469,612 Members | 1,594 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,612 developers. It's quick & easy.

Invoking asp:button click in javascript

JCE
I need to programmatically invoke an asp:Button click event from a
javascript function. The page containing the script and the button is the
HTML page associated with a WebUserControl-derived object (both the HTML and
control are built in the same .ascx file)

The target button simply fires an event in the WebUserControl-derived
object. So, alternatively, if there was a mechanism to call a method
(explicitly or using an event of some sort) in the WebUserControl-derived
object, from this javascript function - this would achieve the goal too,
with one less degree of indirection..

Seems so simple, but I've searched the newsgroups for hours...
Nov 18 '05 #1
2 8778
Take a look at the generated html on the client, and reverse engineer what
you need to do. It will emit an <input type="button" /> or <input
type="submit" />. Grab the ID (you can use the UniqueID property of the
Button object to emit this value, which future proofs your app) and then use
javascript to find the control and call the click method.

--
Chris Jackson
Software Engineer
Microsoft MVP - Windows Client
Windows XP Associate Expert
--
More people read the newsgroups than read my email.
Reply to the newsgroup for a faster response.
(Control-G using Outlook Express)
--

"JCE" <re***@ng.com> wrote in message
news:zn*******************@bignews5.bellsouth.net. ..
I need to programmatically invoke an asp:Button click event from a
javascript function. The page containing the script and the button is the
HTML page associated with a WebUserControl-derived object (both the HTML
and
control are built in the same .ascx file)

The target button simply fires an event in the WebUserControl-derived
object. So, alternatively, if there was a mechanism to call a method
(explicitly or using an event of some sort) in the WebUserControl-derived
object, from this javascript function - this would achieve the goal too,
with one less degree of indirection..

Seems so simple, but I've searched the newsgroups for hours...

Nov 18 '05 #2
JCE
Thank you for your reply.

I think I have tried every permutation of invoking the button click method
in javascript that I can find in the various newsgroups. I always get the
"Page Not Found" error page when the statement executes.

I've used: document.all("Button1").click(); where "Button1" is the ID for
an asp button.

....and document.Form2.Button2.click(); for an HTML INPUT button. (this
statement was built w/ intellisense, so seems legit.)

My app is straightforward, a WebUserControl in an WebForm, all built in .NET
using the visual tools, so don't think I've injected any wierdness into the
situation.

Perhaps you may see something in the syntax above that hints at the problem.
"Chris Jackson" <chrisjATmvpsDOTorgNOSPAM> wrote in message
news:ey**************@TK2MSFTNGP12.phx.gbl...
Take a look at the generated html on the client, and reverse engineer what
you need to do. It will emit an <input type="button" /> or <input
type="submit" />. Grab the ID (you can use the UniqueID property of the
Button object to emit this value, which future proofs your app) and then use javascript to find the control and call the click method.

--
Chris Jackson
Software Engineer
Microsoft MVP - Windows Client
Windows XP Associate Expert
--
More people read the newsgroups than read my email.
Reply to the newsgroup for a faster response.
(Control-G using Outlook Express)
--

"JCE" <re***@ng.com> wrote in message
news:zn*******************@bignews5.bellsouth.net. ..
I need to programmatically invoke an asp:Button click event from a
javascript function. The page containing the script and the button is the HTML page associated with a WebUserControl-derived object (both the HTML
and
control are built in the same .ascx file)

The target button simply fires an event in the WebUserControl-derived
object. So, alternatively, if there was a mechanism to call a method
(explicitly or using an event of some sort) in the WebUserControl-derived object, from this javascript function - this would achieve the goal too,
with one less degree of indirection..

Seems so simple, but I've searched the newsgroups for hours...


Nov 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by giant food | last post: by
2 posts views Thread by Ed Chiu | last post: by
1 post views Thread by RUIZCJ | last post: by
3 posts views Thread by JV | last post: by
2 posts views Thread by DFDavis | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.