By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,835 Members | 1,488 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,835 IT Pros & Developers. It's quick & easy.

Custom Control - Specific placement of HTML Textwriter output - Ho

P: n/a
I have a custom menu control that I am creating using C#. I am rendering
HTML from a StringBuilder in my control to add the needed JavaScript to the
HTML output. I need to have the JavaScript output from the stringbuilder
placed at the bottom of my <BODY> section, after the top navigation menu
dropdown dataset output. Currently the JavaScript is output to the top of
the <BODY> section of my HTML output from the control.

How can I accomplish this?

Thanks,
Hawk
Nov 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
I believe I've done something similar to this before, where I wanted to push
extra controls onto the end of a form. I did this by referencing the form in
my codebehind and then using the Form.Controls.Add(Control) method to add
whichever controls I wanted to create programatically during the PreRender
event.

The PreRender event is effectively the last event to fire before the ASPX
page saves the controls to viewstate, it is the last event available to be
overloaded prior to the page rendering out--it even fires after the Event
Handlers.

Try putting a runat="server" attribute in your body tag (ie: <body
id="bdyPage" runat="server"> of your aspx markup, and then referencing it as
an HtmlGenericControl in your codebehind: protected
System.Web.UI.HtmlControls.HtmlGenericControl bdyPage). Then overload the
ASPX page's PreRender event and output your StringBuilder/JavaScript to the
page at that time. You can expose this through a public method or property
in your custom menu control.

Hope it works/helps.
--
Cheers,

Jonathan

"Hawk" wrote:
I have a custom menu control that I am creating using C#. I am rendering
HTML from a StringBuilder in my control to add the needed JavaScript to the
HTML output. I need to have the JavaScript output from the stringbuilder
placed at the bottom of my <BODY> section, after the top navigation menu
dropdown dataset output. Currently the JavaScript is output to the top of
the <BODY> section of my HTML output from the control.

How can I accomplish this?

Thanks,
Hawk

Nov 17 '05 #2

P: n/a
I think I figured it out... I ended up using a "Literal" and did the following:

//Builds script at bottom of page
System.Text.StringBuilder _BuilderBottom = new
System.Text.StringBuilder();
_BuilderBottom.Append("<script type=\"text/javascript\">\n");
_BuilderBottom.Append(" var nav= new DropDownMenu('Navigation');\n");
_BuilderBottom.Append(" nav.delay.show = 0;\n");
_BuilderBottom.Append(" nav.delay.hide = 400;\n");
_BuilderBottom.Append(" nav.position.levelX.left = 2;\n");
_BuilderBottom.Append(" nav.init();\n");
_BuilderBottom.Append(" </script>\n");

//Adds the javascript to the bottom of the table
Literal javaScriptLiteral = new Literal();
javaScriptLiteral.Text = _BuilderBottom.ToString();
Controls.Add(javaScriptLiteral);

"Jonathan Mast" wrote:
I believe I've done something similar to this before, where I wanted to push
extra controls onto the end of a form. I did this by referencing the form in
my codebehind and then using the Form.Controls.Add(Control) method to add
whichever controls I wanted to create programatically during the PreRender
event.

The PreRender event is effectively the last event to fire before the ASPX
page saves the controls to viewstate, it is the last event available to be
overloaded prior to the page rendering out--it even fires after the Event
Handlers.

Try putting a runat="server" attribute in your body tag (ie: <body
id="bdyPage" runat="server"> of your aspx markup, and then referencing it as
an HtmlGenericControl in your codebehind: protected
System.Web.UI.HtmlControls.HtmlGenericControl bdyPage). Then overload the
ASPX page's PreRender event and output your StringBuilder/JavaScript to the
page at that time. You can expose this through a public method or property
in your custom menu control.

Hope it works/helps.
--
Cheers,

Jonathan

"Hawk" wrote:
I have a custom menu control that I am creating using C#. I am rendering
HTML from a StringBuilder in my control to add the needed JavaScript to the
HTML output. I need to have the JavaScript output from the stringbuilder
placed at the bottom of my <BODY> section, after the top navigation menu
dropdown dataset output. Currently the JavaScript is output to the top of
the <BODY> section of my HTML output from the control.

How can I accomplish this?

Thanks,
Hawk

Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.