473,406 Members | 2,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Help with Webforms component inheritance

Hi everyone!

I am trying to write some "auto-translating" components for an ASP.NET
intranet application.

I started inheriting from label and a made a small control. Also i tested on
the button, they work OK, but I have a question: here is the short code for
the btwButton i made:

Imports System.ComponentModel
Imports System.Web.UI
Imports System.Resources

<DefaultProperty("Text"), ToolboxData("<{0}:btwButton
runat=server></{0}:btwButton>")> Public Class btwButton
Inherits System.Web.UI.WebControls.Button

Private Function TranslateText(ByVal toTranslate As String) As String
Dim r As ResourceManager

Try
r = Page.Application("Translator")
Return r.GetString(toTranslate)
Catch ex As System.Exception
Return toTranslate
End Try
End Function

Protected Overrides Sub Render(ByVal output As
System.Web.UI.HtmlTextWriter)
[Text] = TranslateText([Text]) <<<<< [Text] changes are lost
MyBase.Render(output)
End Sub
End Class

It works as I want, but i'd like to know why the Text property changes after
the first Render are lost, and the next time it renders the control it
returns to the Text property i set in design mode. To make it clear, i'm
happy with this behaviour, but I'd like to know why the Text property gets
resetted to the designtime value... Just in case i'm doing something real
wrong, i'm new to inheriting controls and so on...

TIA

ASC
Nov 18 '05 #1
4 951
"Strange Cat" <st*****@cat.com> wrote in message
news:UB***********************@news3.tin.it...
Hi everyone!

I am trying to write some "auto-translating" components for an ASP.NET
intranet application.

I started inheriting from label and a made a small control. Also i tested on the button, they work OK, but I have a question: here is the short code for the btwButton i made:

Imports System.ComponentModel
Imports System.Web.UI
Imports System.Resources

<DefaultProperty("Text"), ToolboxData("<{0}:btwButton
runat=server></{0}:btwButton>")> Public Class btwButton
Inherits System.Web.UI.WebControls.Button

Private Function TranslateText(ByVal toTranslate As String) As String
Dim r As ResourceManager

Try
r = Page.Application("Translator")
Return r.GetString(toTranslate)
Catch ex As System.Exception
Return toTranslate
End Try
End Function

Protected Overrides Sub Render(ByVal output As
System.Web.UI.HtmlTextWriter)
[Text] = TranslateText([Text]) <<<<< [Text] changes are lost
MyBase.Render(output)
End Sub
End Class

It works as I want, but i'd like to know why the Text property changes after the first Render are lost, and the next time it renders the control it
returns to the Text property i set in design mode. To make it clear, i'm
happy with this behaviour, but I'd like to know why the Text property gets
resetted to the designtime value... Just in case i'm doing something real
wrong, i'm new to inheriting controls and so on...


Render is too late to make changes like that. Try making the change in
PreRender.
--
John Saunders
johnwsaundersiii at hotmail
Nov 18 '05 #2
[CUT]
Render is too late to make changes like that. Try making the change in
PreRender.


Thanx for answering, John. I'm happy with the behaviour of my very small
component, as I need the text to be resetted like that. I was just thinking
if it is legal to change Text property in the Render event handler, well if
it works... it must be legal, I guess.

Thanx

ASC
Nov 18 '05 #3
"Strange Cat" <st*****@cat.com> wrote in message
news:uS***********************@news4.tin.it...
[CUT]
Render is too late to make changes like that. Try making the change in
PreRender.
Thanx for answering, John. I'm happy with the behaviour of my very small
component, as I need the text to be resetted like that. I was just

thinking if it is legal to change Text property in the Render event handler, well if it works... it must be legal, I guess.


BTW, "if it works it must be legal" is a bad assumption. It may only seem to
work (meaning you haven't tested for the cases where it doesn't work), or it
may only work in this release and won't work in the next release.
--
John Saunders
johnwsaundersiii at hotmail
Nov 18 '05 #4
> BTW, "if it works it must be legal" is a bad assumption. It may only seem
to
work (meaning you haven't tested for the cases where it doesn't work), or it may only work in this release and won't work in the next release.


I guess you're right...

So i have tried also overriding the OnPrerender event in my small components
and the behaviour is the same, i can change the text property there, the
control gets rendered with the new text property, but on the next
OnPrerender event, the text property returns as I set it at design time...
still have to figure out why, but, again that's what I wanted.

Thanx John for answering

ASC
Nov 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Tee | last post by:
Hi, I have a base usercontrol with a method (blank method, no code), I have another few usercontrols that will inherit this base usercontrol, but I want to force all the usercontrol that...
4
by: orangepic333 | last post by:
Could someone tell me what's the difference between the two? Is it that a class is used within an OO language while a component can be exported between OO languages? Are there other...
7
by: Jack Addington | last post by:
I've got a fairly simple application implementation that over time is going to get a lot bigger. I'm really trying to implement it in a way that will facilitate the growth. I am first writing a...
2
by: Paul M | last post by:
Hi there, can anyone help me with this one.... i have a page which is in normal english format, but when i wanna change it to Russian format text, i set the Culture code, but it still remains...
0
by: Lucas Tam | last post by:
Are there any free flowcharting type components for webforms? I found some for Java, but nothing really for ASP.NET. I know of several commercial products such as GoDiagram, Syncfusion's...
2
by: Simon | last post by:
Hi, Just to get started.... I've created a very simple web form, "Simple", using VS and I dropped a HTML img control on the design view. I referenced a picture and it is displayed in browser...
4
by: 3Cooks | last post by:
I have a windows application written in Visual Basic 6.0 that is going to be redeveloped in dotNET. We are trying to decide if we should deploy using Webforms or Winforms and I need advice from...
122
by: Edward Diener No Spam | last post by:
The definition of a component model I use below is a class which allows properties, methods, and events in a structured way which can be recognized, usually through some form of introspection...
1
by: Wendi Turner | last post by:
Configuration Error from Visual Studio 2005 .NET 2.0 This is an ASP.NET Website with a Report Viewer Component - Microsoft.ReportViewer.WebForms & .Common included in project output Trying to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
marktang
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,...
0
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...
0
Oralloy
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,...
0
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...
0
agi2029
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.