Activating JavaScript from C#

  • Thread starter Thread starter Mike Strauss
  • Start date Start date
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
 
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
 
-----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)
 
Back
Top