Invoking asp:button click in javascript

  • Thread starter Thread starter JCE
  • Start date Start date
J

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...
 
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.
 
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.
 
Back
Top