Viewstate Issue?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: SS (stephen_at_acsalaska.com)
Date: 06/23/04


Date: Wed, 23 Jun 2004 14:02:11 -0800

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
  }



Relevant Pages

  • Viewstate Issue?
    ... I've build a custom control that's essentially a header for my web site. ... Within the render ... // Begin Image Cell ...
    (microsoft.public.dotnet.framework.aspnet.webcontrols)
  • Re: Viewstate Issue?
    ... > I've build a custom control that's essentially a header for my web site. ... Within the render ... > 'refreshes' in the design view, ... > // Begin Image Cell ...
    (microsoft.public.dotnet.framework.aspnet.buildingcontrols)
  • Re: Viewstate Issue?
    ... > I've build a custom control that's essentially a header for my web site. ... Within the render ... > 'refreshes' in the design view, ... > // Begin Image Cell ...
    (microsoft.public.dotnet.framework.aspnet.buildingcontrols)
  • Re: Viewstate Issue?
    ... > I've build a custom control that's essentially a header for my web site. ... Within the render ... > 'refreshes' in the design view, ...
    (microsoft.public.dotnet.framework.aspnet.buildingcontrols)
  • Re: Excel: AddIn, fill active sheet cell ?
    ... So I dont think your going to be able to modify a cell other than the one ... private CommandBarButton m_Button; ... OnStartupComplete(ref custom); ... public void OnDisconnection(Extensibility.ext_DisconnectMode ...
    (microsoft.public.dotnet.languages.csharp)