ABB
ABB

Reputation: 557

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 manager 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

Upvotes: 0

Views: 1945

Answers (1)

Dustin Laine
Dustin Laine

Reputation: 38503

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);  
}

Upvotes: 1

Related Questions