Re: Viewstate Issue?
From: Teemu Keiski (joteke_at_aspalliance.com)
Date: 06/24/04
- Previous message: Cappy: "Re: viewstate for collapsable panel control"
- In reply to: SS: "Viewstate Issue?"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 24 Jun 2004 21:58:52 +0300
Hi,
can you also show the code for the collection property?
-- Teemu Keiski MCP, Microsoft MVP (ASP.NET), AspInsiders member ASP.NET Forum Moderator, AspAlliance Columnist http://blogs.aspadvice.com/joteke "SS" <stephen@acsalaska.com> wrote in message news:eTNx92WWEHA.3492@TK2MSFTNGP10.phx.gbl... > Hi, > I've build a custom control that's essentially a header for my web site. > It's pretty simple, with just a property for an image source path, and a > collection of custom objects for links. > > The custom class simply has properties for href, target, and name. The > collection implements CollectionBase. > > The elements of the collection are persisted as innerdefaultproperties, so > within the tag for the custom control, child elements are present > representing my custom link objects. > > The control's render method uses HtmlTextWriter.AddAttribute and > RenderBeginTag/RenderEndTag methods to produce the html. Within the render > method, a foreach loop goes through my collection and renders anchor tags > with the appropriate attributes. > > When I place the header control onto a web page, it renders fine. I can edit > the collection of 'links' with the stock design-time editor, and the links > render perfectly when as I add or remove links from the collection. > > The problem is, when I do a build on my web app (the page) the page > 'refreshes' in the design view, and my links have disappeared. The HTML view > (in VS) still shows the child elements for the links I added, but when I > switch back to design view, they don't render (no errors, just acts like the > don't exist). Indeed, when I click on the "..." to open up the collection > editor, it's empty, even though the HTML is still there. > > I haven't even gotten to where I'm rendering this in a browser, since I > can't get it to hold on to links through the build process. Any ideas on > what I'm doing wrong here? I've been thinking that perhaps I need to build > some viewstate management code, but then I also think that this shouldn't be > an issue for the particular problem I'm having -- not getting my collection > to get rerendered in the designer after a build.. > > Thanks for any help! > > Here's my render method: > protected override void Render(HtmlTextWriter output) > { > output.AddAttribute(HtmlTextWriterAttribute.Id,"tblHeader"); > output.AddAttribute(HtmlTextWriterAttribute.Border,"0"); > output.AddAttribute(HtmlTextWriterAttribute.Cellpadding, "0"); > output.AddAttribute(HtmlTextWriterAttribute.Cellspacing, "0"); > output.AddStyleAttribute(HtmlTextWriterStyle.Width, "100%"); > output.RenderBeginTag(HtmlTextWriterTag.Table); > > // Begin Table Row > output.RenderBeginTag(HtmlTextWriterTag.Tr); > // Begin Image Cell > output.AddStyleAttribute(HtmlTextWriterStyle.Height,"121"); > output.AddAttribute(HtmlTextWriterAttribute.Valign, "top"); > output.RenderBeginTag(HtmlTextWriterTag.Td); > output.AddAttribute(HtmlTextWriterAttribute.Src,this.ImageSrc); > output.AddAttribute(HtmlTextWriterAttribute.Border,"0"); > output.AddAttribute(HtmlTextWriterAttribute.Alt,"Home"); > output.RenderBeginTag(HtmlTextWriterTag.Img); > output.RenderEndTag(); > output.RenderEndTag(); > // End Image Cell > // Begin Empty Cell > output.AddStyleAttribute(HtmlTextWriterStyle.Height,"121"); > output.AddAttribute(HtmlTextWriterAttribute.Valign, "top"); > output.RenderBeginTag(HtmlTextWriterTag.Td); > output.Write(@" "); > output.RenderEndTag(); > // End Empty Cell > // Begin Data Cell > output.AddStyleAttribute(HtmlTextWriterStyle.Height,"121"); > output.AddAttribute(HtmlTextWriterAttribute.Valign, "top"); > output.RenderBeginTag(HtmlTextWriterTag.Td); > output.AddAttribute(HtmlTextWriterAttribute.Id,"lblDate"); > output.RenderBeginTag(HtmlTextWriterTag.Span); > output.WriteLine(DateTime.Now.ToShortDateString()); > output.RenderEndTag(); > output.RenderEndTag(); > output.RenderEndTag(); > // End Data Cell > > // Begin Table Row > output.RenderBeginTag(HtmlTextWriterTag.Tr); > // Begin Link Cell > output.AddAttribute(HtmlTextWriterAttribute.Colspan,"3"); > output.AddAttribute(HtmlTextWriterAttribute.Valign,"top"); > output.AddAttribute(HtmlTextWriterAttribute.Align,"left"); > output.AddAttribute(HtmlTextWriterAttribute.Class,this.HeaderMenuClass); > output.RenderBeginTag(HtmlTextWriterTag.Td); > foreach (CustomLink objLink in this.Links) > { > output.AddAttribute(HtmlTextWriterAttribute.Class, > (objLink.CssClass.Length > 0) ? objLink.CssClass : this.LinkClass); > output.AddAttribute(HtmlTextWriterAttribute.Href,objLink.NavigateUrl); > output.AddAttribute(HtmlTextWriterAttribute.Target,objLink.Target); > output.AddAttribute(HtmlTextWriterAttribute.Alt, objLink.ToolTip); > output.RenderBeginTag(HtmlTextWriterTag.A); > output.Write(objLink.Text); > output.RenderEndTag(); > } > output.RenderEndTag(); > // End Link Cell > output.RenderEndTag(); > // End Table Row > } > >
- Previous message: Cappy: "Re: viewstate for collapsable panel control"
- In reply to: SS: "Viewstate Issue?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|