473,387 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Custom Control - Specific placement of HTML Textwriter output - Ho

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
2 4361
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Chris Pels | last post by:
I am sending the XML output of an XslTranform to a StringWriter and the <xml> header has an encoding type of "utf-16" which IE 6 does not like/support. How do I get the encoding value in the output...
8
by: Lawrence Oluyede | last post by:
Is there a way to treat html tags like simple text? I explain myself, if I have a bunch of xml like <content type="application/xhtml+xml" xml:base="http://loluyede.blogspot.com" xml:lang="en-US"...
3
by: Joe Bloggs | last post by:
Does anyone know if its possible to pass parameters or the values of Request.QueryString from a web page to a custom control class? I'm using a C# Web Application. For Example I have Web Page1...
19
by: Dales | last post by:
I have a custom control that builds what we refer to as "Formlets" around some content in a page. These are basically content "wrapper" sections that are tables that have a colored header and...
2
by: Jay Walker | last post by:
I created a custom DataGridColumn based on Marcie Robillard's MSDN Article: Creating Custom Columns for the ASP.NET Datagrid...
4
by: DKode | last post by:
I have developed a custom server control that displays a login page that authenticates against AD. The server control works fine, but now I am trying to figure out the best way to output custom...
4
by: sreedhar.cs | last post by:
Hi all, In my application,I want to place a vector in a specific location in shared memory.(a user supplied pointer). I understand that the STL allocator mechanism places the data objects within...
4
by: Charles Zhang | last post by:
I created a custom server control whose rendering logic relies on session variables and cookies. It works just fine at run time. The problem is at the design time, because session variables and...
5
by: gerry | last post by:
I am trying to create a custom container control that will only ever contain a specific type of control. At design time, when a control of a different type is added to the container I would like...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.