Başka bir sayfaya yönlendirildikten sonra JavaScript'i işin arkasında koduma nasıl getirebilirim? Bir asp buton kontrolüm var ve o düğmeye tıkladığımda uyarmak istiyorum, sonra başka bir sayfaya gidin. Kodumda (JS kodundan önce veya sonra) bir Response.Redirect
bulunduğumda, 8 denemenin hiçbiri çalışmaz. Yönlendirme yaptığımda, birkaç (2,7 & 8) çalışır.Kod Yönlendirme ile JavaScript uyarısı
//Try one
ScriptManager.RegisterStartupScript(this, GetType(), "test", "alert('test1');", true);
//Try two
ClientScript.RegisterClientScriptBlock(typeof(Page), "test", "test2");
//Try three
Page.ClientScript.RegisterStartupScript(this.GetType(), "CallMyFunction", "alertMessage()", true);
//Try four
ClientScript.RegisterStartupScript(GetType(), "CallMyFunction", "alertMessage()", true);
//Try five
ClientScript.RegisterStartupScript(GetType(), "CallMyFunction", "javascript: alertMessage(); ", true);
//Try six
ClientScript.RegisterClientScriptBlock(GetType(), "CallMyFunction", "<script>alert('test4')</script>");
//Try seven
Response.Write("<script>alert('test5');</script>");
//Try eight
string script = "alert('test6')";
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "CallMyString", script, true);
response.redirect("pageUrlHere");
//With this code above, none of the js functions (alerts) work
//response.redirect("pageUrlHere");
//With this commented out, try 2, 7 and 8 work.
JS işlevi:
function alertMessage() {
alert('test3');
}
Teşekkürler arkadaşı çalışır! –
Endişeye gerek yok, bu yardımcı oldu :) – chridam
Küçük bir değişiklik, sayfa adı ScriptManager.RegisterStartupScript (bu, this.GetType(), "yönlendirme", "uyarı ('test 9') önce pencere gerekir. location = '"+ Request.ApplicationPath +" /anotherpage.aspx'; ", true);' – n00b