RegisterClientScriptBlock without form tag?

As far as I know this functions the same in current versions, you can test it very simply though.

Up vote 2 down vote favorite share g+ share fb share tw.

After trying to understand why client code is not rendered in a page (injected by user control) I found this link, it turns out you must have a form tag for it to work (Page. RegisterClientScriptBlock did declare this but ClientScriptManager. RegisterClientScriptBlock which I use does not say anything regarding this).

I am using Visual studio 2005. Does anyone know if this has been solved? Edit: To clarify, I want my control to add javascript code to the head section of the page without having to use the InnerText = "alert('123');"; Page.Header.Controls.

Add(x); But this did not work for me. Asp.net javascript registerclientscriptblock link|improve this question edited Jan 26 '09 at 15:47 asked Jan 26 '09 at 14:57Dror3,2471018 100% accept rate.

As far as I know this functions the same in current versions, you can test it very simply though. Update per discussion in the comments, the only "workaround" that I could think of would be for your to manually insert the script into the "head" section of the page on your own, using a runat="server" declaration on the Head element.

I did test it and it does not work without the form tag. Is there any work-around so I don't have to use the form runat='server'? – Dror Jan 26 '09 at 15:17 Edited answer with a bit of detail.

– Mitchel Sellers Jan 26 '09 at 15:25.

Got it! My mistake was not doing it in the OnPreRender method (I used the Render method). Now all that is needed is - like Mitchel Sellers wrote, set the header to runat server and than add to it's controls: HtmlGenericControl x = new HtmlGenericControl("script"); x.

InnerText = GetScriptSection(); Page.Header.Controls. Add(x); Thanks for pointing me to the right direction!

The MSDN Page for registerclientscriptblock here says: The client-side script is emitted just after the opening tag of the Page object's element. The script block is emitted as the object that renders the output is defined, so you must include both tags of the element. If you do not want to include a form, than you will basically need to build your own implementation of it.

What do you mean by "build your own implementation of it" - I have no use for the form itself, I just want the script to be added to the page. – Dror Jan 26 '09 at 15:35.

Minor clarification for anyone seeing this: The form tag must have the runat="server" attribute set, e.g. Just placing a regular HTML form tag in the page will not help.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions