Web User Control not accepting Property...Set calls

  • Thread starter Thread starter Wayne M J
  • Start date Start date
W

Wayne M J

WUC: PageHeader
Prop: Heading (Get/Set)

I have dragged and dropped an instance of the WUC onto the webform, and have
referenced it:
Protected PageHeader1 as PageHeader

If I do a `Return PageHeader1.Heading` I successfully get the current
heading in this case I get a string of nothing per-se.

However, if I attempt `PageHeader1.Heading = "Some Text"`, Debug shows it
goes through the motions, the ASP:Label is shown to have received the text
"Some Text", but once the page is fully loaded, I am greeted with a blank
ASP:Label.

I have tried another approach to this problem, by:
Private Sub Page_Load (...)
Dim MyHeader as Control

MyHeader = LoadControl("PageHeader.ascx")
Page.Controls.AddAt(0, MyHeader)
Response.Write ("--[" & Ctype(MyHeader, PageHeader).Heading & "]--")
'Shows: --[]--
Ctype(MyHeader, PageHeader).Heading = "Some text"
' Actually Shows "Some Text" in the label
End Sub

Isn't that piece of code just the long winded version of the above.
Is this a bug, if so is it my code or theirs (MS) or is this by design?
 
In the user control, when are you setting the values from the properties. In
other words, when are you taking the value that that are handled by the set
routing and applying them to the label. If you're setting it in the
Page_Load event of the web user control that's the wrong spot. Instead, set
the label text in the OnPreRender event instead.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage
 
Mark Fitzpatrick said:
In the user control, when are you setting the values from the properties. In
other words, when are you taking the value that that are handled by the set
routing and applying them to the label. If you're setting it in the
Page_Load event of the web user control that's the wrong spot. Instead, set
the label text in the OnPreRender event instead.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage

I am setting them in the Page_Load event of the `hosting` WebForm; would
perhaps a similar edit to the PreRender of the hosting WebForm be prudent?
 
You should be fine setting it in the Page_Load event of the host form, just
access it during the OnPreRender event of the control.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage
 
Back
Top