Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JS and C#

Status
Not open for further replies.

copeZero

Programmer
Aug 31, 2007
46
CA
I i was wondering if there way a way tyo have these two scripts work together:
Code:
string JscriptFinal = "<script type='text/javascript'>window.onload=function(){alert('asdf');}</script>";

Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "key", JscriptFinal);

AND

Code:
Response.Redirect("aaa.aspx?Count=" + includeitems)

So the response.redirect does not happen until JS has fired the alert.

Thanks
 
That just isn't possible. Response is a server command. For the alert to happen, the page must load.

You have (at least) 2 options. First, you could forget the server side response redirect and just do

Code:
string JscriptFinal = "<script type='text/javascript'>window.onload=function(){alert('asdf');window.location = 'aaa.aspx?Count=" + includeitems + "';"}</script>";

That would just do the redirect client-side.

Additionally, you could show the alert and then submit the page again (after javascript sets a flag to show that the alert has happened) to have the redirect handled by the server.

Note: I didn't test the code above, so I could have a typo or something in there, but the logic is what you need to do.

----------------------------------------

TWljcm8kb2Z0J3MgIzEgRmFuIQ==
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top