.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Generic Casting to access Text property

Posted By:      Posted Date: September 23, 2010    Points: 0   Category :ASP.Net

I have a situation where I'm iterating through all the controls on a form, specifically looking out for any of these three types of controls:  Labels, TextBoxes, CheckBoxes

I can, of course, get the type of the control and then use a Switch-Case construct to cast labels as Labels, textboxes as TextBoxes, and checkboxes as CheckBoxes.

But I'm wondering if there's a way to do something with one or two lines of code to gain access to the Text property of each of these controls?

I'm guessing this isn't possible but thought I'd ask to be sure,


View Complete Post

More Related Resource Links

Access the SQL Command Query Value Property from the OLEDB Container within a Script Task

Hello, I'd like to Access the SQL Command Query Value Property from the OLEDB Container within a Script Task so I can audit the queries which are executing. What is the syntax for this or does anyone have a sample on how to do this? Thank you

text box binding with Generic list

Hi, I am working in asp.net 3.5 page, where I want to bind a textbox with generic list data. And I have Previous & next button. Which will show the record in textbox. I don't want to go in db again and again.  Is it possible.??? 

How Do I Not Include: myControl.GetType.GetProperty("Text") When No Property Window Setting?

Hi All, Posted below is code I'm using to generate a list of controls that have either a "Text" or "Caption" property. However, for certain controls in the resulting list, the property setting (Text/Caption) does not appear in the "Property Window" of the IDE when that control is selected. One example of this is the Systems.Windows.Forms.PictureBox control. Is there a way I can determine this and if so - how do I exclude these control(s) from my list?     Private Sub cmdValidateControls_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdValidateControls.Click         txtResults.Clear()         For Each ctrl As Object In Me.Controls             LogControl(ctrl)         Next     End Sub     Private Sub LogControl(ByVal ctrlIn As Object)         If System.Diagnostics.Debugger.IsAttached Then             If (Not ctrlIn.GetType.GetProperty("Text") Is Nothing) Or (Not ctrlIn.GetType.GetProperty("Caption") Is Nothing) Then                 txtRes

How can I access a Type with generic parameter in XAML

Hello, How can I access a Type with generic parameter in XAML. class SampleClass<T> { } now in XAML: i want to access xmlns:local="Ref to SampleClass" How it will create the instance of SampleClass<T>?

how to get and set radiobutton value without using text property?

I need 10 radiobuttons, but I do not want to use radiobutton list and I am not able to use Text property since I mark the Text for radiobutton in another row. All the radiobuttons' text are set as empty string. How can I get and set the value for the radiobuttons. Thanks.  <div>             <div> &nbsp;</div>            <div>                <span>1</span>&nbsp;&nbsp;                <span>2</span>&nbsp;&nbsp;                <span>3</span>&nbsp;&nbsp;            </div>            <div>                <span>4</span>&nbsp;&nbsp;                <span>5</span>&nbsp;&nbsp;            &n

Textbox Text Property

I am new to VB and I have read that if I don't explicity cast variable types it will eat up performance. I have been casting certain objects, such as values from data readers, but I was wondering if the object has a property that says it is a string, like the textbox "Text" property, if I need to still cast that as a string.   Right now my code says "txtSearch.Text" but should I be using "txtSearch.Text.ToString()"?   Thanks in advance for the help!

saving a text file in ms access data base

i have to read a text file in a text box then have to save it into ms access data base in column format how could i do this....

Weird casting error (storing Generic list in Session)


Am trying to store a generic list in Session to act as a simple shopping cart. Am getting a weird casting error when I try and retrieve it from Session.

A critical error has occurred.
[A]System.Collections.Generic.List`1[MyCartItem] cannot be cast to [B]System.Collections.Generic.List`1[MyCartItem].
Type A originates from 'mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089'
    in the context 'LoadNeither' at location 'C:\WINDOWS\assembly\GAC_32\mscorlib\\mscorlib.dll'.
Type B originates from 'mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089'
    in the context 'LoadNeither' at location 'C:\WINDOWS\assembly\GAC_32\mscorlib\\mscorlib.dll'.

I have a class variable defined:

List<MyCartItem> _cart;

In the Load event I have:

_cart = (Session["MyCart"] != null) ? (List<MyCartItem>)Session["MyCart"] : new List<MyCartItem>();

Dynamic Generic Casting


Hi guys

I am wanting to do some dynamic casting/variable creation with some generics but am having a little trouble. Essentially, the type of the generic need to be the same as a given variable. As such a simple example would be something like this but obviously it doesn't work:


Code Block

int value = 10;

Type type = value.GetType();

List<type> list = new List<type>();


The exmaple that i have is something like this:

Modal Popup - Unable to set label text property



I have ajax accordion with 6 panes with an user control inside each of it.
 In the first pane I have a form view user control and have a modalpopup to
display error message. The same method is used in all other panes.

On page load I was able to set the label text property and it properly shows in modal popup.

However whenever I do some validation and update label text property, the modal popup
shows up but the label text property is not updated. It works in all other panes.

The only difference is the user control in the pane is inside of a update panel. If I remove the

update panel every thing works fine. But I need the update panel to avoid full post back.

How do I set the label text property inside of a modal popup.

Sections of code below:




protected void Page_Load(object sender, EventArgs e)
        lblNewMessage.Text = "Error";

 protected void FormView1_ItemCommand(object sender, FormViewCommandEventArgs e)
	 if (!doValidate() ) { return; }
    public bool doValidate()
        if (!psClassUtil.check_isnull_or_empty(firstName, 30, "N"))
            lblNewMessage.Text = "First Name is required (Maximum 30 characters)."; // does not 

How can i access claaes Property values in xml file ?



actually i am creating sitemap.sitemap is actually an xml file.And i have stored each page's url  of my project as Public shared property of a class.Now while creating sitemap xml file i want to get access to those property on my class, so that url should not be hardcoded.How can i do that ?

Please help .

How to access the Parent form Text box in Third iframe


i have 3 iframe how to access the paten(t textbox value=1) in the 3rd iframe

How to set a style's TargetType property in XAML to a Generic Class?


I've just moved to .NET 4.0 / Visual Studio 2010 and am hoping there is a new answer to this question, found on StackOverflow from over a year ago:

Is it possible to set a style's TargetType property in XAML to a Generic Class?

public class Selector<T> : Control { }

and then in xaml

<Style x:TargetType="Selector">
<Setter Property="MyProperty" Value="Green" />

I found this on the WPF Tutorial, and would like to find a similar mechanism for this situation above.

<!-- XAML 2009 -->
<ObservableCollection x:TypeArguments="Employee">
 <l:Employee FirstName="John" Name="Doe" />
 <l:Employee FirstName="Tim" Name="Smith" />
</ObservableCollection />



Unable to access custom extended property


When I try to access the .ExtendedProperties["RequestChangeRequired"].ToString() in the onTaskChanged_Invoked method on a workflow I get the error:  "Object Not Set To Instance of an Object".

I have a custom content type on a task list in a custom workflow.  I want to set my Task to either Approved, Major Change or Minor Change.  So i have 3 buttons on the .aspx page for the content type when the users edit the task.  If they click the Minor button the following code is executed:

public void BtnMinor_Click(object sender, EventArgs e)
            Hashtable taskHash = new Hashtable();
            taskHash["RequestReviewerComment"] = RequestReviewerComment.Text;
            taskHash["RequestApproved"] = "false";
            taskHash["RequestChangeRequired"] = "minor";
            taskHash["Approved"] = "false";
            taskHash["Status"] = "complete";
            SPWorkflowTask.AlterTask(m_task, taskHash, true);

            SPUtility.Redirect(List.DefaultViewUrl, SPRedirectFlags.UseSource, HttpContext.Current);

Then in my onTaskChanged_Invoked method the following code is executed but it fals when it tries to access the "RequestChangeRequired

How to access property values in the model that you are binding to? - Help!


From within a custom modelBinder (derived from DefaultModelBinder), how do I access the existing values of properties in the model into which the new values are being injected?

Thanks in advance for your help!

Access Denied error when i try to create a text file using vc++ project.



I have vc++ API project which  installes custom tool bar to adobe acrobat. I need to add a text file using this project. when i try to do it it's working in my computer, but when i run this api in another computer, it's giving access denied.

I am using Windows 7 and Visual Studio 8 for this project.

Please can any one give a suggestion or any other method to solve this issue.


ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend