Connecting Tech Pros Worldwide Help | Site Map

A composite control

  #1  
Old November 19th, 2005, 12:02 PM
James T.
Guest
 
Posts: n/a
Hello!

I developed a composite control that inherits from HyperLink and overrides
Render method.

In web form I am using this control with DataGrid. On DataGrid ItemDataBound
event I set ImageWidth and ImageHeight values programmatically. But on
post-back the control loses ImageWidth and ImageHeight values.

What I am doing wrong?

Thank you!
James


CODE:
-----------------------

Protected Overrides Sub Render(ByVal Output As System.Web.UI.HtmlTextWriter)

Output.AddAttribute(HtmlTextWriterAttribute.Href, Me.NavigateUrl)
Output.RenderBeginTag(HtmlTextWriterTag.A)

If ImageUrl.Length = 0 Then
Output.Write([Text])
Else

Output.AddAttribute(HtmlTextWriterAttribute.Src, ImageUrl)
Output.AddAttribute(HtmlTextWriterAttribute.Alt, [Text])
Output.AddAttribute(HtmlTextWriterAttribute.Height , ImageHeight)
Output.AddAttribute(HtmlTextWriterAttribute.Width, ImageWidth)

If Not (ImageHeight Is Nothing) Then
Output.AddAttribute(HtmlTextWriterAttribute.Height , ImageHeight)
End If

If Not (ImageWidth Is Nothing) Then
Output.AddAttribute(HtmlTextWriterAttribute.Width, ImageWidth)
End If

Output.RenderBeginTag(HtmlTextWriterTag.Img)
Output.RenderEndTag()

End If
Output.RenderEndTag()

End Sub


  #2  
Old November 19th, 2005, 12:03 PM
Yunus Emre ALPÖZEN [MCAD.NET]
Guest
 
Posts: n/a

re: A composite control


you should save your values in a viewstate or a inline property... It loses
its state..

--

Thanks,
Yunus Emre ALPÖZEN
BSc, MCAD.NET

"James T." <gimenei@hotmail.com> wrote in message
news:eXOwwA%23WFHA.3348@TK2MSFTNGP14.phx.gbl...[color=blue]
> Hello!
>
> I developed a composite control that inherits from HyperLink and overrides
> Render method.
>
> In web form I am using this control with DataGrid. On DataGrid
> ItemDataBound event I set ImageWidth and ImageHeight values
> programmatically. But on post-back the control loses ImageWidth and
> ImageHeight values.
>
> What I am doing wrong?
>
> Thank you!
> James
>
>
> CODE:
> -----------------------
>
> Protected Overrides Sub Render(ByVal Output As
> System.Web.UI.HtmlTextWriter)
>
> Output.AddAttribute(HtmlTextWriterAttribute.Href, Me.NavigateUrl)
> Output.RenderBeginTag(HtmlTextWriterTag.A)
>
> If ImageUrl.Length = 0 Then
> Output.Write([Text])
> Else
>
> Output.AddAttribute(HtmlTextWriterAttribute.Src, ImageUrl)
> Output.AddAttribute(HtmlTextWriterAttribute.Alt, [Text])
> Output.AddAttribute(HtmlTextWriterAttribute.Height , ImageHeight)
> Output.AddAttribute(HtmlTextWriterAttribute.Width, ImageWidth)
>
> If Not (ImageHeight Is Nothing) Then
> Output.AddAttribute(HtmlTextWriterAttribute.Height , ImageHeight)
> End If
>
> If Not (ImageWidth Is Nothing) Then
> Output.AddAttribute(HtmlTextWriterAttribute.Width, ImageWidth)
> End If
>
> Output.RenderBeginTag(HtmlTextWriterTag.Img)
> Output.RenderEndTag()
>
> End If
> Output.RenderEndTag()
>
> End Sub
>[/color]


  #3  
Old November 19th, 2005, 12:03 PM
Steve C. Orr [MVP, MCSD]
Guest
 
Posts: n/a

re: A composite control


You should probably be storing those values in ViewState between postbacks.
Here's an example of a custom control that uses ViewState to store similar
custom values and retrieve them again when needed.
http://SteveOrr.net/articles/InheritAndExtend.aspx

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net


"James T." <gimenei@hotmail.com> wrote in message
news:eXOwwA%23WFHA.3348@TK2MSFTNGP14.phx.gbl...[color=blue]
> Hello!
>
> I developed a composite control that inherits from HyperLink and overrides
> Render method.
>
> In web form I am using this control with DataGrid. On DataGrid
> ItemDataBound event I set ImageWidth and ImageHeight values
> programmatically. But on post-back the control loses ImageWidth and
> ImageHeight values.
>
> What I am doing wrong?
>
> Thank you!
> James
>
>
> CODE:
> -----------------------
>
> Protected Overrides Sub Render(ByVal Output As
> System.Web.UI.HtmlTextWriter)
>
> Output.AddAttribute(HtmlTextWriterAttribute.Href, Me.NavigateUrl)
> Output.RenderBeginTag(HtmlTextWriterTag.A)
>
> If ImageUrl.Length = 0 Then
> Output.Write([Text])
> Else
>
> Output.AddAttribute(HtmlTextWriterAttribute.Src, ImageUrl)
> Output.AddAttribute(HtmlTextWriterAttribute.Alt, [Text])
> Output.AddAttribute(HtmlTextWriterAttribute.Height , ImageHeight)
> Output.AddAttribute(HtmlTextWriterAttribute.Width, ImageWidth)
>
> If Not (ImageHeight Is Nothing) Then
> Output.AddAttribute(HtmlTextWriterAttribute.Height , ImageHeight)
> End If
>
> If Not (ImageWidth Is Nothing) Then
> Output.AddAttribute(HtmlTextWriterAttribute.Width, ImageWidth)
> End If
>
> Output.RenderBeginTag(HtmlTextWriterTag.Img)
> Output.RenderEndTag()
>
> End If
> Output.RenderEndTag()
>
> End Sub
>[/color]


Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Control, Web Control and Composite Control shapper answers 6 December 26th, 2007 02:55 PM
Composite Control - Control sizing Eric answers 3 September 13th, 2007 11:45 AM
Composite control's oninit won't fire multiformity@gmail.com answers 0 May 30th, 2006 08:15 PM
ATL composite control hangs in MFC Paul Kia answers 1 December 13th, 2005 07:05 PM
How to add pager control for Composite Control. Satya Bojanapally answers 0 November 16th, 2005 05:00 AM