Page.RegisterClientScriptBlock() is not working ..... :-(

V

Vipul Pathak

Hi,

I am writing a WebControl. With that I need to emit JavaScript code on the
page. For that I am using "Page.RegisterClientScriptBlock" method inside the
PreRender event. It is shocking to see that the the method takes the script
to emit, but does not actually emit it on the page. Neither it throws any
exception.

I am emiting JavaScript from 2 places: PreRender event and Render event. In
PreRender, I am using Page.RegisterClientScriptBlock() and In Render I am
using output.Write(). It could be noticed that output.Write() is working,
but Page.RegisterClientScriptBlock() is not.

What might be the reason? Any Help ?

Thanks,

** Vipul ;

PS: Also to note, RegisterStartupScript() is working from PreRender.
=======================================
VIPUL PATHAK
Impetus Infotech India Pvt. Limited,
Indore, MP, India.
 
B

Brock Allen

Did you look at the HTML source of the rendered page to make sure it's not
being emitted? Did you wrap your javascript with <script language=javascript></script>?
PreRender should be fine for doing this.
 
V

Vipul Pathak

Yes, I have done all that ...

** Vipul ;



Brock Allen said:
Did you look at the HTML source of the rendered page to make sure it's not
being emitted? Did you wrap your javascript with <script
 
B

Brock Allen

I'd suggest building the smallest app you can where this doesn't work. When
I build a page that does as you suggest it works fine (RegisterClientScriptBlock
in PreRender).
 
M

Mythran

Vipul Pathak said:
Hi,

I am writing a WebControl. With that I need to emit JavaScript code on the
page. For that I am using "Page.RegisterClientScriptBlock" method inside
the
PreRender event. It is shocking to see that the the method takes the
script
to emit, but does not actually emit it on the page. Neither it throws any
exception.

I am emiting JavaScript from 2 places: PreRender event and Render event.
In
PreRender, I am using Page.RegisterClientScriptBlock() and In Render I am
using output.Write(). It could be noticed that output.Write() is working,
but Page.RegisterClientScriptBlock() is not.

What might be the reason? Any Help ?

Thanks,

** Vipul ;

PS: Also to note, RegisterStartupScript() is working from PreRender.
=======================================
VIPUL PATHAK
Impetus Infotech India Pvt. Limited,
Indore, MP, India.

Yes, we had this before. The reason is, I believe, you are registering the
script too late. Try registering the script before PreRender is called...in
a different event or method?

Mythran
 

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,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top