473,386 Members | 1,798 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,386 software developers and data experts.

getting the ID of the current server control

TB
Hi All:

What would be the right way to get the ID of a server control inside an
event for that same server control?

For example:

I have this textbox called textbox1 which the following event code attached:

Private Sub textbox1_TextChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handlestextbox1.TextChanged
if textbox1.Text.ToString() = "This is it" then
' something happens
end if
End Sub

Now, since I have lot of these textboxes with similar events, I would like
to make a generic code line (maybe for a sub), replacing "textbox1.Text"
with something like (pseudocode) "CurrentControl.Text"

What would be the right reference?

Thanks

TB
Mar 15 '06 #1
4 1119
Hi TB:

The sender parameter is your TextBox... all you need to do is cast it
to a TextBox DataType:
Dim oText As TextBox
oText = CType( sender, TextBox )

That (or something like it) should do it for you.

Mar 15 '06 #2
The "Sender" parameter of the event gives you a reference to the control that
sent it.

in VB.NET the "Me" keyword provides a reference to the current class
instance, in C#, "this".

So if you cast "Sender" to the control's type, you can get its ID and every
other property inside your single "generic" eventhandler's code.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"TB" wrote:
Hi All:

What would be the right way to get the ID of a server control inside an
event for that same server control?

For example:

I have this textbox called textbox1 which the following event code attached:

Private Sub textbox1_TextChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handlestextbox1.TextChanged
if textbox1.Text.ToString() = "This is it" then
' something happens
end if
End Sub

Now, since I have lot of these textboxes with similar events, I would like
to make a generic code line (maybe for a sub), replacing "textbox1.Text"
with something like (pseudocode) "CurrentControl.Text"

What would be the right reference?

Thanks

TB

Mar 15 '06 #3
TB
Thanks a lot.

TB
"Ceberhard" <ce*******@tampabay.rr.com> wrote in message
news:11**********************@u72g2000cwu.googlegr oups.com...
Hi TB:

The sender parameter is your TextBox... all you need to do is cast it
to a TextBox DataType:
Dim oText As TextBox
oText = CType( sender, TextBox )

That (or something like it) should do it for you.

Mar 16 '06 #4
TB
Thanks a lot for your advice.

TB

"Peter Bromberg [C# MVP]" <pb*******@yahoo.nospammin.com> wrote in message
news:B5**********************************@microsof t.com...
The "Sender" parameter of the event gives you a reference to the control
that
sent it.

in VB.NET the "Me" keyword provides a reference to the current class
instance, in C#, "this".

So if you cast "Sender" to the control's type, you can get its ID and
every
other property inside your single "generic" eventhandler's code.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"TB" wrote:
Hi All:

What would be the right way to get the ID of a server control inside an
event for that same server control?

For example:

I have this textbox called textbox1 which the following event code
attached:

Private Sub textbox1_TextChanged(ByVal sender As System.Object, ByVal e
As
System.EventArgs) Handlestextbox1.TextChanged
if textbox1.Text.ToString() = "This is it" then
' something happens
end if
End Sub

Now, since I have lot of these textboxes with similar events, I would
like
to make a generic code line (maybe for a sub), replacing "textbox1.Text"
with something like (pseudocode) "CurrentControl.Text"

What would be the right reference?

Thanks

TB

Mar 16 '06 #5

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

Similar topics

4
by: Larry Tate | last post by:
I am wanting to get those cool html error pages that ms produces when I hit an error in asp.net. For instance, when I get a compilation error I get an html error page that shows me the ...
11
by: KarimL | last post by:
Thanks for your advices... but i need to get the Image height because i dynamically resize the height of my webcontrol based on the image height. More i just have the url (relative parth) to the...
2
by: Chad | last post by:
In our application, I would like to send out HTML mail. TO do so, I must do something like this: Mail.Body = <raw HTMLTEXT String> Hence, I would like to know how to get the HTML text for Web...
5
by: Nathan Sokalski | last post by:
I have a user control that contains three variables which are accessed through public properties. They are declared immediately below the "Web Form Designer Generated Code" section. Every time an...
1
by: vijaykumars | last post by:
+-----------------------------------------------------------------------------+ Summaries: +-----------------------------------------------------------------------------+ Installation...
3
by: =?Utf-8?B?c3BkMzAwMQ==?= | last post by:
I have a C++/CLI app that uses a logging control in an ATL COM Server. C++ Interop seems to work just fine to pass data from the C++/CLI app to the ATL Control but I can't seem to figure out how...
1
by: showbizzansh | last post by:
Server Error in '/ExportReport' Application. -------------------------------------------------------------------------------- Method 'ISCREditableRTFExportFormatOptions_reserved5' on type...
0
by: aboutjav.com | last post by:
Hi, I need some help. I am getting this error after I complete the asp.net register control and click on the continue button. It crashed when it tries to get it calls this Profile property ...
1
by: Jordan S. | last post by:
Using .NET 3.5, I'm wondering how to get a control's specific type (e.g,. "Button" and not simply "Control") after the control is inserted into a control hierarchy - when ParseControl is used. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
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,...

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.