views:

100

answers:

3
public void DisplayThickBox(Page page, int width, int height)
    {
        string script = "<script type='text/javascript'>";
        script += "$(document).ready(function(){";
        script += "tb.show('null', 'auto-insurance-redirect.aspx?keepThis=true&TB_iframe=true&height=" + height.ToString() + "&amp;width=" + width.ToString() + "',null);";
        script += "});";
        script +="</script>";

        ScriptManager.RegisterStartupScript(page, page.GetType(), "", script, true);

    }

^^^Method to display the thickbox...^^^

DisplayThickBox(this, 518, 321);

^^^Call to method in the click event of the button that fires it...^^^

Page is just refreshing and the thickbox is never displayed. I'm trying to call the javascript manually since im doing some other stuff before i display the thickbox in the code behind...

A: 

Sounds like you're calling this on a button click event which would postback to the server. You'll need to register the javascript on the client and call it from javascript, not thru server side code. What you have now is a startup script which should run when the page loads, that's not really what you want.

Shawn Steward
Shouldnt it fire that javascript right after the postback the click event fires though?for reference purposes, I'm trying to follow the following demo: http://pocketpollster.com/apps/ThickBoxDemo/ Not sure why his is successful and mine isnt :(
Alex
Throw an alert('Hello') in before your tb.show line to see if you're even getting to that portion of the javascript.
Shawn Steward
@Shawn: Do you think it would be wise to pull the JavaScript into a .js file, reference it from the aspx page, and then add the event handlers in the .js file? I firmly believe in unobtrusive JavaScript but I'm not sure of its appropriateness within ASP.NET.
Mayo
not getting to the alert...crap! Something must be wrong with the way I'm building my script call in the code behind?...
Alex
weird...I even tried ScriptManager.RegisterStartupScript(page, page.GetType(), "", "alert('" + script + "');" , true);and it wont even throw an alert at me...
Alex
A: 

Looking at your javascript parameters:

"tb.show('null', 'auto-insurance-redirect.aspx?keepThis=true&TB_iframe=true&height=" + height.ToString() + "&amp;width=" + width.ToString() + "',null);"

I notice that some parameters are separated by & and others are separated by &amp;. Maybe this is the problem.

Keltex
tried it both ways and it still doesn't show the thickbox. Thanks for the suggestion though.
Alex
A: 

Got it fixed, no idea how...I had tried so many things and everything was getting dirty and clustered, so I took everything out and started back from blank and it worked right off the bat.

Thanks everyone for their help!

Alex