Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Viewstate Issue?

Thread Tools

Viewstate Issue?

Posts: n/a
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,"tb lHeader");
output.AddAttribute(HtmlTextWriterAttribute.Border ,"0");
output.AddAttribute(HtmlTextWriterAttribute.Cellpa dding, "0");
output.AddAttribute(HtmlTextWriterAttribute.Cellsp acing, "0");
output.AddStyleAttribute(HtmlTextWriterStyle.Width , "100%");

// Begin Table Row
// Begin Image Cell
output.AddStyleAttribute(HtmlTextWriterStyle.Heigh t,"121");
output.AddAttribute(HtmlTextWriterAttribute.Valign , "top");
output.AddAttribute(HtmlTextWriterAttribute.Src,th is.ImageSrc);
output.AddAttribute(HtmlTextWriterAttribute.Border ,"0");
output.AddAttribute(HtmlTextWriterAttribute.Alt,"H ome");
// End Image Cell
// Begin Empty Cell
output.AddStyleAttribute(HtmlTextWriterStyle.Heigh t,"121");
output.AddAttribute(HtmlTextWriterAttribute.Valign , "top");
output.Write(@" ");
// End Empty Cell
// Begin Data Cell
output.AddStyleAttribute(HtmlTextWriterStyle.Heigh t,"121");
output.AddAttribute(HtmlTextWriterAttribute.Valign , "top");
output.AddAttribute(HtmlTextWriterAttribute.Id,"lb lDate");
output.WriteLine(DateTime.Now.ToShortDateString()) ;
// End Data Cell

// Begin Table Row
// Begin Link Cell
output.AddAttribute(HtmlTextWriterAttribute.Colspa n,"3");
output.AddAttribute(HtmlTextWriterAttribute.Valign ,"top");
output.AddAttribute(HtmlTextWriterAttribute.Align, "left");
output.AddAttribute(HtmlTextWriterAttribute.Class, this.HeaderMenuClass);
foreach (CustomLink objLink in this.Links)
(objLink.CssClass.Length > 0) ? objLink.CssClass : this.LinkClass);
output.AddAttribute(HtmlTextWriterAttribute.Href,o bjLink.NavigateUrl);
output.AddAttribute(HtmlTextWriterAttribute.Target ,objLink.Target);
output.AddAttribute(HtmlTextWriterAttribute.Alt, objLink.ToolTip);
// End Link Cell
// End Table Row

Reply With Quote

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
Problems with ViewState: "function 'ViewState.get_Item' evaluated and returned null" Steph ASP .Net 2 05-11-2011 02:35 PM
Errors: Failed to load viewstate. & Validation of viewstate MAC failed. sck10 ASP .Net 6 09-01-2006 05:59 PM
Loading usercontrols, viewstate problem, slighly different from all others "viewstate uc problems" please help... ujjc001 ASP .Net 0 07-27-2005 01:52 PM
Viewstate errors... how do I get viewstate working? mark ASP .Net Building Controls 0 02-20-2004 02:17 PM
Corrupted ViewState (Yes, another issue concerning viewstate) Ben Rush ASP .Net 2 12-05-2003 04:17 PM