Activating JavaScript from C#

M

Mike Strauss

Mission impossible?

I would like to click on a button on an aspx page, have that trigger a
section of code in the code behind, then depending of the results of the
code behind execution, execute a JavaScript.

The JavaScript I need to execute is a "window.open", but only if the results
of the code execute as expected.

I believe I could dynamically create the JavaScript in the code behind and
add it using RegisterStartupScript. That would allow me to conditinally
execute the JavaScript. In other words, I could simply add blank function
if I needed to not open the window.

However, how could I trigger it to execute on the button click after
executing a call back function?

Any ideas?

Thanks,
Scott
 
W

WJ

Mike Strauss said:
Mission impossible?

However, how could I trigger it to execute on the button click after
executing a call back function?

JS is client code, not server code, therefore, the "button click" must also
be client control in order for the JS event to be triggered, not server
control. So my guess here is that you would use the Html Form control button
instead, and assign the JS onButtonClick event to the Html form control
(button). Then on PageLoad event, just register the JS events and you are
good to go.

John
 
E

Elton Wang

-----Original Message-----
Mission impossible?

I would like to click on a button on an aspx page, have that trigger a
section of code in the code behind, then depending of the results of the
code behind execution, execute a JavaScript.

The JavaScript I need to execute is a "window.open", but only if the results
of the code execute as expected.

I believe I could dynamically create the JavaScript in the code behind and
add it using RegisterStartupScript. That would allow me to conditinally
execute the JavaScript. In other words, I could simply add blank function
if I needed to not open the window.

However, how could I trigger it to execute on the button click after
executing a call back function?

Any ideas?

Thanks,
Scott


.
I suppose it's possible.

1. Create label control, lblScript.
2. Create button, btnOpenWindow
3. In btnOpenWindow_Click
if(condition){
lblScript.Text = Script command
}
else{
lblScript.Text = "";
}


Hope it's helpful

Elton Wang
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top