tags:

views:

203

answers:

1

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
+1  A: 

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);  
}
Dustin Laine
Thanks, I tried that and it just blinks at me. I know the JavaScript works because I have a "close" text link on my page tied to the Javascript function as well and that works.
ABB
What blinks? the page?
Dustin Laine
Yes. The entire interstitial page blinks like it tried to do something but nothing happened.
ABB
Do you have the scriptmanager on your page?
Dustin Laine
I'm unable to get put it on my page without error. It gives me a "error creating control" every time I try to put it on my form. That's why I was wondering if there was another way to do this besides using the scriptmanager.
ABB
This is the recommended way, I believe you can also place a literal control on your page and set the value to the script text.
Dustin Laine
I'll keep working on trying to get the scriptmanager to work. Thanks for your help!
ABB