Hello!
An common issue for me is that I have a web control, double-click it to
reach the event in the code-behind. Then I for example get the code:
protected void CheckBox1_CheckedChanged(Object sender , EventArgs e)
This is good, but if I then want to use the sender as a control, for
instance the methods are not for the Checkbox, but for the Object.
This is quite obvious, but how to solve it?
I can't (or it's not recommended to) write if (sender.Checked == true)...
Should I convert it, and if so, how?
Regards Magnus 4 992
Easy
Dim myControlName as ControlTypeLikeTexBoxOrWhaterver
myControlName = DirectCast( sender, ControlTypeLikeTexBoxOrWhaterver )
myControlName.WhateverPropertyYouWantToSetIsNow = "OK"
"Magnus Blomberg" <ma*************@skanska.se> wrote in message
news:et**************@tk2msftngp13.phx.gbl... Hello!
An common issue for me is that I have a web control, double-click it to reach the event in the code-behind. Then I for example get the code: protected void CheckBox1_CheckedChanged(Object sender , EventArgs e)
This is good, but if I then want to use the sender as a control, for instance the methods are not for the Checkbox, but for the Object. This is quite obvious, but how to solve it? I can't (or it's not recommended to) write if (sender.Checked == true)... Should I convert it, and if so, how?
Regards Magnus
Hello Magnus,
I think it is preferred to first check the type before casting the instance
to another Class.
Regards,
Mark Monster Hello!
An common issue for me is that I have a web control, double-click it to reach the event in the code-behind. Then I for example get the code: protected void CheckBox1_CheckedChanged(Object sender , EventArgs e)
This is good, but if I then want to use the sender as a control, for instance the methods are not for the Checkbox, but for the Object. This is quite obvious, but how to solve it? I can't (or it's not recommended to) write if (sender.Checked == true)... Should I convert it, and if so, how? Regards Magnus
Thanks!
The problem is that this function is VB, and I'm using C#. Do you now
the opposit for C#?
Regards Magnus
*** Sent via Developersdex http://www.developersdex.com ***
Magnus,
In C# you use an "Explicit Cast"" so working from the previous example:
ControlTypeLikeTextBoxOrWhatever myControlName;
myControlName = (ControlTypeLikeTextBoxOrWhatever) sender;
myControlName.WhateverPropertyYouWantToSetIsNow = "OK";
--
Sincerely,
S. Justin Gengo, MCP
Web Developer / Programmer www.aboutfortunate.com
"Out of chaos comes order."
Nietzsche
"Magnus Blomberg" <ma*************@skanska.se> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl... Thanks! The problem is that this function is VB, and I'm using C#. Do you now the opposit for C#?
Regards Magnus
*** Sent via Developersdex http://www.developersdex.com *** This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: aevans1108 |
last post by:
expanding this message to microsoft.public.dotnet.xml
Greetings
Please direct me to the right group if this is an inappropriate place
to post this question. Thanks.
I want to format a...
|
by: Phil Stanton |
last post by:
When designing a new form or report, the Default ForeColor is often
something like -2147483640 which is the colour of Windows text (possibly
black) and the default backColor is -2147483643...
|
by: Alan Silver |
last post by:
Hello,
I have installed the 2.0 framework, and am looking at converting some of
my 1.1 pages to use partial classes. I don't (yet) have VS2005, so I'm
doing this by hand, but am having problems....
|
by: Nikolay Petrov |
last post by:
How can I convert DOS cyrillic text to Unicode
|
by: Me |
last post by:
Hi all
I am getting a really bizzare error on when I convert a string into a
datetime:
The code is :
DateTime dt1 = Convert.ToDateTime("10 Sep 2005");
Console.WriteLine(dt1.Year);
|
by: Learner |
last post by:
Hello,
Here is the code snippet I got strucked at.
I am unable to convert the below line of code to its equavalent vb.net
code. could some one please help me with this?
static public...
|
by: Carlo3030 |
last post by:
Been reading Dino Esposito's Article "A DetailsView Control for ASP.NET 1.x"
found in the msdn Library. His example was created using VB.NET. I am trying
to convert the example (DetailsView...
|
by: PenguinPig |
last post by:
Dear All Experts
I would like to know how to convert a HTML into Image using C#. Or allow me
contains HTML code (parsed) in Image? I also tried this way but it just
display the character "<" &...
|
by: JJ |
last post by:
I've got an n-layer application that fetches data from an SQL database using
stored procedures.
This information is read into various classes which represent a hierachical
structure:.
eg.
...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| | |