Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / February 2008

Tip: Looking for answers? Try searching our database.

Emitting Client Script

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ed Courtenay - 15 Feb 2008 19:41 GMT
Reposting here as you can practically see the tumbleweed blow by in
microsoft.public.dotnet.framework.aspnet.webcontrols....

I've got a very simple custom control that requires a small section of
JavaScript to function at the client - nothing out of the ordinary.

In the overridden RenderContents method of my custom control I check
whether the required client script block has been registered with
Page.ClientScript.IsClientScriptBlockRegistered() and if not, register
it with Page.ClientScript.RegisterClientScriptBlock()

If I place the custom control on a web form, the script gets injected
into the page as expected and works as it should.

If, however, the control is placed onto a Master page the script doesn't
get injected and therefore the control fails to work; why is this
behaving differently when the control is placed on a Master page, and
what do I have to do to get it to work?
bruce barker - 15 Feb 2008 21:11 GMT
RenderContents is the wrong time to register the script. as the script block
comes before the controls html, its too late to render it after you have
rendered the content. Suprised your code ever worked.

move the RegisterClientScriptBlock to OnPreRender where it belongs.

-- bruce (sqlwork.com)

> Reposting here as you can practically see the tumbleweed blow by in
> microsoft.public.dotnet.framework.aspnet.webcontrols....
[quoted text clipped - 14 lines]
> behaving differently when the control is placed on a Master page, and
> what do I have to do to get it to work?
Ed Courtenay - 15 Feb 2008 22:18 GMT
> RenderContents is the wrong time to register the script. as the script block
> comes before the controls html, its too late to render it after you have
[quoted text clipped - 3 lines]
>
> -- bruce (sqlwork.com)

How the hell did I miss that? *blush*

It's strange what you miss when it's staring you straight in the face!

>> Reposting here as you can practically see the tumbleweed blow by in
>> microsoft.public.dotnet.framework.aspnet.webcontrols....
[quoted text clipped - 14 lines]
>> behaving differently when the control is placed on a Master page, and
>> what do I have to do to get it to work?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.