register start up script hell

A

AmitKu

I'm trying to use RegisterStartupScript.

I am making a call to it in Page_Load...and nothing shows up. Well
that not's entirely true. Half the pages I've put it on do work
properly, but the other half just don't work at all. Nothing shows up
at all.

How can I debug this? What are possible causes?

Thanks,
Amit
 
A

AmitKu

Just so you know...I deleted everything and tried this and it still
failed....

protected void Page_Load( object sender, EventArgs e )
{
string newscript = "<script>hello</script>";
Page.ClientScript.RegisterStartupScript( this.GetType(),
"randomScript", newscript );
bool fDidItWork = Page.ClientScript.IsStartupScriptRegistered(
"randomScript" );
}

and fDidItWork = false at the end of this.

Why??

--Amit
 
G

Guest

Hi,
Just change following line of code:
Incorrect One :string newscript = "<script>hello</script>";
Correct One:string newscript = "<script>alert('Hello ASP.NET'); </script>";

if it is still not working then let me know

Thanks and regards,
manish bafna
 
G

Guest

Hi,
you can try following code also:

Page.ClientScript.RegisterStartupScript(this.GetType(), "randomScript",
" alert('Hello ASP.NET'); ", true);

In the previous example, you are specifying a Boolean value setting of True
so that .NET places the script on the ASP.NET page with <script> tags
automatically.

Thanks and Regards,
manish bafna
 
A

AmitKu

Nope doesn't work at all...same result.

I was originally using some real javascript, before even trying just
the "hello" to see if anything would work. So it's not a matter of
using real javascript.

--Amit
 
B

bruce barker

when you register the script, you use the type object to create a
namespace for register scripts. when you check if registered you do not
pass the type so you are checking in a different namespace, so it
responds no.

when you register a startup script it is rendered just before the
</form>. as long as there are no redirect, transfer, response.end or
clear content calls it should render.

-- bruce (sqlwork.com)
 
A

AmitKu

Hi Bruce,

You were right about IsStartupScript....but the thing just doesn't show
up. I don't know what to tell you....no redirect, transfer,
response.end or clear content calls are made.

What could I be doing wrong?

Thanks,
Amit
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top