C# run Javascript from button click
I have a button on my .aspx interstitial page. When I click it the onClick event fires off and it does a bunch of validations in the code. I have a javascript function that I need to call/run AFTER these validations are performed. This javascript function closes the interstitial page. How can I call the javascript function from my C# code? I've tried adding a script mana开发者_如何学Pythonger and a client script but neither work. What else besides these two options do I have? I'd be willing to use a hack if it works. Javascript I'm using:
javascript:parent.interstitialBox.closeit(); return false
On your button click you need to registerstartupscript..
protected void Button1_Click(object sender, EventArgs e)
{
//Your validation
string scriptclose = "parent.interstitialBox.closeit(); return false;";
ScriptManager.RegisterStartupScript(this, this.GetType(), "closeScript", scriptclose, true);
}
精彩评论