473,325 Members | 2,442 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,325 software developers and data experts.

Override Render - adding user control

I'm trying to add a user control to a form via the pages render method and I
get the following error :

"Control 'Button1' of type 'Button' must be placed inside a form tag with
runat=server"

The user control has this button on its page. I am outputing the <form
runat="server"> inside the render method and have also tried adding it to
the page and to the control without any luck. Any help appreciated.

Output of the page without the user control being rendered :

<html>
<body><form id="Form1" method="post" runat="server">
<table border=1>
<tr>
<td>
<span id="Label1">my Text</span>
</td>
<td>
</td>
</tr>
</table>
</form></body>
</html>

Render method :

protected override void Render(HtmlTextWriter writer)
{
PlaceHolder myPlaceHolder = new PlaceHolder();

string str = "ZText.ascx";
Control myControl = LoadControl(str);
myPlaceHolder.Controls.Add(myControl);

string str2 = "ZButton.ascx";
Control myControl2 = LoadControl(str2);
myPlaceHolder.Controls.Add(myControl2);

StreamReader sr = new StreamReader(Request.PhysicalApplicationPath +
"PaneLayout.zp");
String line;

while ((line = sr.ReadLine()) != null)
{
if (line.IndexOf("<body>") == 0)
{
writer.Write(line);
writer.Write(@"<form id=""Form1"" method=""post"" runat=""server"">");
writer.WriteLine();
}
else if (line.IndexOf("</body>") == 0)
{
writer.Write(@"</form>");
writer.Write(line);
writer.WriteLine();
}

else if (line.IndexOf("ZText") > 0)
{
myControl.RenderControl(writer);
}
else if (line.IndexOf("ZButton") > 0)
{
myControl2.RenderControl(writer);
}
else
{
writer.Write(line);
writer.WriteLine();
}
}

sr.Close();

base.Render (writer);
}
Nov 19 '05 #1
3 5131
John,

Put a Placholder Control on the page where you want your control to appear.

Then add the control to the Placeholder.

Placeholder.Controls.Add

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"John Hughes" <jh******@msn.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
I'm trying to add a user control to a form via the pages render method and
I get the following error :

"Control 'Button1' of type 'Button' must be placed inside a form tag with
runat=server"

The user control has this button on its page. I am outputing the <form
runat="server"> inside the render method and have also tried adding it to
the page and to the control without any luck. Any help appreciated.

Output of the page without the user control being rendered :

<html>
<body><form id="Form1" method="post" runat="server">
<table border=1>
<tr>
<td>
<span id="Label1">my Text</span>
</td>
<td>
</td>
</tr>
</table>
</form></body>
</html>

Render method :

protected override void Render(HtmlTextWriter writer)
{
PlaceHolder myPlaceHolder = new PlaceHolder();

string str = "ZText.ascx";
Control myControl = LoadControl(str);
myPlaceHolder.Controls.Add(myControl);

string str2 = "ZButton.ascx";
Control myControl2 = LoadControl(str2);
myPlaceHolder.Controls.Add(myControl2);

StreamReader sr = new StreamReader(Request.PhysicalApplicationPath +
"PaneLayout.zp");
String line;

while ((line = sr.ReadLine()) != null)
{
if (line.IndexOf("<body>") == 0)
{
writer.Write(line);
writer.Write(@"<form id=""Form1"" method=""post"" runat=""server"">");
writer.WriteLine();
}
else if (line.IndexOf("</body>") == 0)
{
writer.Write(@"</form>");
writer.Write(line);
writer.WriteLine();
}

else if (line.IndexOf("ZText") > 0)
{
myControl.RenderControl(writer);
}
else if (line.IndexOf("ZButton") > 0)
{
myControl2.RenderControl(writer);
}
else
{
writer.Write(line);
writer.WriteLine();
}
}

sr.Close();

base.Render (writer);
}

Nov 19 '05 #2
I'm already using a placeholder control to place my user controls.
"S. Justin Gengo" <sjgengo@[no_spam_please]aboutfortunate.com> wrote in
message news:O%****************@tk2msftngp13.phx.gbl...
John,

Put a Placholder Control on the page where you want your control to
appear.

Then add the control to the Placeholder.

Placeholder.Controls.Add

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"John Hughes" <jh******@msn.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
I'm trying to add a user control to a form via the pages render method
and I get the following error :

"Control 'Button1' of type 'Button' must be placed inside a form tag with
runat=server"

The user control has this button on its page. I am outputing the <form
runat="server"> inside the render method and have also tried adding it to
the page and to the control without any luck. Any help appreciated.

Output of the page without the user control being rendered :

<html>
<body><form id="Form1" method="post" runat="server">
<table border=1>
<tr>
<td>
<span id="Label1">my Text</span>
</td>
<td>
</td>
</tr>
</table>
</form></body>
</html>

Render method :

protected override void Render(HtmlTextWriter writer)
{
PlaceHolder myPlaceHolder = new PlaceHolder();

string str = "ZText.ascx";
Control myControl = LoadControl(str);
myPlaceHolder.Controls.Add(myControl);

string str2 = "ZButton.ascx";
Control myControl2 = LoadControl(str2);
myPlaceHolder.Controls.Add(myControl2);

StreamReader sr = new StreamReader(Request.PhysicalApplicationPath +
"PaneLayout.zp");
String line;

while ((line = sr.ReadLine()) != null)
{
if (line.IndexOf("<body>") == 0)
{
writer.Write(line);
writer.Write(@"<form id=""Form1"" method=""post""
runat=""server"">");
writer.WriteLine();
}
else if (line.IndexOf("</body>") == 0)
{
writer.Write(@"</form>");
writer.Write(line);
writer.WriteLine();
}

else if (line.IndexOf("ZText") > 0)
{
myControl.RenderControl(writer);
}
else if (line.IndexOf("ZButton") > 0)
{
myControl2.RenderControl(writer);
}
else
{
writer.Write(line);
writer.WriteLine();
}
}

sr.Close();

base.Render (writer);
}


Nov 19 '05 #3
John,

No, put the placeholder in the page code don't create it in your
code-behind.

<html>
<body><form id="Form1" method="post" runat="server">
<table border=1>
<tr>
<td>
<span id="Label1">my Text</span>
<asp:placeholder id="MyPlaceholder" runat=server>
</td>
<td>
</td>
</tr>
</table>
</form></body>
</html>

Then just add your controls to that.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"John Hughes" <jh******@msn.com> wrote in message
news:OG**************@TK2MSFTNGP09.phx.gbl...
I'm already using a placeholder control to place my user controls.
"S. Justin Gengo" <sjgengo@[no_spam_please]aboutfortunate.com> wrote in
message news:O%****************@tk2msftngp13.phx.gbl...
John,

Put a Placholder Control on the page where you want your control to
appear.

Then add the control to the Placeholder.

Placeholder.Controls.Add

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"John Hughes" <jh******@msn.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
I'm trying to add a user control to a form via the pages render method
and I get the following error :

"Control 'Button1' of type 'Button' must be placed inside a form tag
with runat=server"

The user control has this button on its page. I am outputing the <form
runat="server"> inside the render method and have also tried adding it
to the page and to the control without any luck. Any help appreciated.

Output of the page without the user control being rendered :

<html>
<body><form id="Form1" method="post" runat="server">
<table border=1>
<tr>
<td>
<span id="Label1">my Text</span>
</td>
<td>
</td>
</tr>
</table>
</form></body>
</html>

Render method :

protected override void Render(HtmlTextWriter writer)
{
PlaceHolder myPlaceHolder = new PlaceHolder();

string str = "ZText.ascx";
Control myControl = LoadControl(str);
myPlaceHolder.Controls.Add(myControl);

string str2 = "ZButton.ascx";
Control myControl2 = LoadControl(str2);
myPlaceHolder.Controls.Add(myControl2);

StreamReader sr = new StreamReader(Request.PhysicalApplicationPath +
"PaneLayout.zp");
String line;

while ((line = sr.ReadLine()) != null)
{
if (line.IndexOf("<body>") == 0)
{
writer.Write(line);
writer.Write(@"<form id=""Form1"" method=""post""
runat=""server"">");
writer.WriteLine();
}
else if (line.IndexOf("</body>") == 0)
{
writer.Write(@"</form>");
writer.Write(line);
writer.WriteLine();
}

else if (line.IndexOf("ZText") > 0)
{
myControl.RenderControl(writer);
}
else if (line.IndexOf("ZButton") > 0)
{
myControl2.RenderControl(writer);
}
else
{
writer.Write(line);
writer.WriteLine();
}
}

sr.Close();

base.Render (writer);
}



Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: DesignerX | last post by:
I want to draw the radiobuttons (each listitem) in a different place than the default of under or beside each other. Does anyone know how this is possible? Thanks, Stan
3
by: Jason Dean | last post by:
Hello, I have a simple asp:label control that I want to write some complicated HTML to. Currently I have this code and it works fine: myLable.Text = "<p>this is my text</p>" Bust as my...
2
by: Ronen | last post by:
Hi, I am writing a grid Web control library. The grid has some client side JavaScript to enable columns resize, sorting, row selection etc. I have some problems adding the JavaScript...
4
by: Zuel | last post by:
Hi Folks. So I have a small problem. My DoPostBack function is not writen to the HTML page nor are the asp:buttons calling the DoPostBack. My Goal is to create a totaly dynamic web page where...
0
by: milmus tender | last post by:
Hi, we have some customized EditorParts, which inherits from a DefaultEditor. This DefaultEditorPart inherits from the standard EditorPart-Class. In this DefaultEditorPart we override the...
2
by: =?Utf-8?B?bG91aXNlIHJhaXNiZWNr?= | last post by:
HI there. I use IE7. We have a user with bad eyesight. he cannot read the font when IE makes an input disabled (the light grey color font). I am able to change the background to a different color...
3
by: Allan Ebdrup | last post by:
We're pretty new to ASP.Net 2.0 and we're having a discussion about best practice when developing custom server web controls. I can see that in for example the Wizard control the table contained...
0
by: JDeats | last post by:
I need to be able to detect when the user clicks on the browser control area. The control offers no Mouse events whatsoever. I have tried to resort to override WndProc on the control, I have a...
1
by: Joshua | last post by:
I'm creating a web control that has an image and a text box. I would like to then override the Visible and Text property of the usercontrol, so when you reference the visible property of the user...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.