Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > render not rendering literal controls

Reply
Thread Tools

render not rendering literal controls

 
 
geoff
Guest
Posts: n/a
 
      04-15-2004
I'm working on project where I find a control on a page and then
insert a literal control (a tag) directly before it with the
form.controls.addat method. I stepped through the code and used the
immediate window to show all the controls in the form controls
collection, and the literalcontrol that I added was there where it was
supposed to be. But, when the page displayed in the browser, it
wasn't in the html. This event is occurring after the containing
page's oninit and page load events have already fired. Is that why
it's not rendering it because the page's form control collection has
already been rendered to the page and adding more controls at this
point would have no effect? If so, how else could I do this? Thanks.
 
Reply With Quote
 
 
 
 
Scott
Guest
Posts: n/a
 
      04-17-2004

There are lots of places (and events) where you should be able to do this; the important thing is that it's done before the control tree is rendered; below is a sample.

Scott

<%@ Page language="c#" AutoEventWireup="false" trace="true" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html>
<head>
<script language="C#" runat="server">
protected override void OnPreRender(EventArgs e)
{
Control c = FindControl("Label1");
LiteralControl l = new LiteralControl("<strong>hello</strong>");
l.ID = "PreLit";
int i = 0;
foreach (Control child in c.Parent.Controls)
{
if (child == c)
{
c.Parent.Controls.AddAt(i, l);
break;
}
++i;
}
}
</script>
</head>
<body>
<form id="Form1" method="post" runat="server">
<p>
<asp:Label id="Label1" runat="server">Label</asp:Label></p>
<p>&nbsp;</p>
<p>
<asp:Button id="Button1" runat="server" Text="Button"></asp:Button></p>

</form>
</body>
</html>


"geoff" <(E-Mail Removed)> wrote in message news:(E-Mail Removed). ..
I'm working on project where I find a control on a page and then
insert a literal control (a tag) directly before it with the
form.controls.addat method. I stepped through the code and used the
immediate window to show all the controls in the form controls
collection, and the literalcontrol that I added was there where it was
supposed to be. But, when the page displayed in the browser, it
wasn't in the html. This event is occurring after the containing
page's oninit and page load events have already fired. Is that why
it's not rendering it because the page's form control collection has
already been rendered to the page and adding more controls at this
point would have no effect? If so, how else could I do this? Thanks.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Rendering Server Controls in literal text =?Utf-8?B?Sm9l?= ASP .Net 14 10-24-2005 06:21 PM
What's wrong with rpc-literal? Why use doc-literal? Anonieko Ramos ASP .Net Web Services 0 09-27-2004 09:06 AM
Page.Render do not render complete page Lau Lei Cheong ASP .Net 1 05-15-2004 04:10 AM
Problem overriding render method to format literal content of nested tags in custom control Stephen Miller ASP .Net Building Controls 12 01-20-2004 08:52 AM
Rendering literal and serveral controls nested in web control at design time Stephen Miller ASP .Net Building Controls 1 01-02-2004 01:26 AM



Advertisments