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 3477
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." <gi*****@hotmail.com> wrote in message
news:eX****************@TK2MSFTNGP14.phx.gbl... 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
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." <gi*****@hotmail.com> wrote in message
news:eX****************@TK2MSFTNGP14.phx.gbl... 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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Satya Bojanapally |
last post by:
Hi,
I am unable to add a pager for this composite control.
I had created a composite control in C#. The control is having 5 labels, one radio button and one DropDownList control. The composite...
|
by: Paul Kia |
last post by:
I have an ATL composite control which I drop into a tab control dialog page
of an MFC application. When I click on the composite control and then click
anywhere outside the MFC application, the...
|
by: sleigh |
last post by:
Hello,
I'm building a web application that will build a dynamic form based
upon questions in a database. This form will have several different
sections that consist of a panel containing one to...
|
by: dx |
last post by:
I have the Microsoft Press: Developing Microsoft ASP.NET Server Controls and
Components book. It's starting to shine some light on control development
but there is something about composite...
|
by: Jeff |
last post by:
Hi -
I am developing a composite control using VB.NET.
In the ASP.NET page using the control, How can I update a label text value
to reflect the value of a property of the custom control...
|
by: Mark Olbert |
last post by:
This involves a family of related, databound ASPNET2 composite controls.
I've managed to arrange things so that the composite controls restore themselves from ViewState on postback after they're...
|
by: multiformity |
last post by:
Ok, so I have gone off and documented the lifecycle of a page with a
custom composite control on it. You can find that document here:
http://www.ats-engineers.com/lifecycle.htm
Now, I am...
|
by: Beavis |
last post by:
I hate to repost a message, but I am still at the same point where I
was when I originally posted, and hopefully someone else will see this
one...
Ok, so I have gone off and documented the...
|
by: Eric |
last post by:
I have created a fairly basic composite control consisting of a Label
and a TextBox. In the overridden Render function, I'm creating a
table with two rows and each row contains a cell (td). The...
|
by: shapper |
last post by:
Hello,
I am working in a class library with various custom controls.
In which cases should a control inherit Control, WebControl and
CompositeControl classes?
And when should a custom...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |