Friday, March 12, 2010

Changing properties of textbox in visual studio 2010

Changing properties of textbox in visual studio 2010
To change the properties of the textbox at run time we need a textbox whose properties we will be changed and an event on which we can see the changes that we have made are applied so to solve the purpose of an event I have taken a command button or button whose click event will work for as the triggering event.
A Design view is shown here.
There are three controls:
And following changes are made to their properties.

            ID: lbl_Name
            Backcolor: Aqua
            BorderColor: #660066
BorderStyle: Double
BorderWidth: 5px
            Bold: True
            Italic: True
            Name: Book Antiqua
            ForeColor: Red
            Text: Name
ToolTip: Enter Your First Name

ID: txt_name
Accesskey: n
            ID : btn_click
Text: Click

Then you can either double click on the button in the Default.aspx page or you can double click on the combobox in the properties window under events in front of click event in order to generate the click event.
Once you will do that you will see the following window.

And in this window you can write the following code.
protected void btn_click_Click(object sender, EventArgs e)
            txt_name.TextMode = TextBoxMode.MultiLine;
            txt_name.Text="My name is Meetu ";

This will change the mode of the textbox to multiline and the text as well.
The following code will be executed when the text of the textbox will be changed but here is a catch if you will not change the autopostback property of the textbox to true this event wont execute and the default value for autopostback is false as in most of the cases we do not prefer a textbox to call the code form the server side.

        protected void txt_name_TextChanged(object sender, EventArgs e)
            lbl_Name.Text = "event called";
Now you can run the program and check these properties and events and can try changing more properties.

Thanks and Regards
Meetu Choudhary
Microsoft MVP (ASP.Net)
DNS MVM Awardee | Microsoft Certified Professional | Microsoft Certified Technology Specialist |
Co-founder / Webmaster : | | | Lead Editor / Webmaster : |  | | | My Blog : | My Profile :

No comments:

Post a Comment

Subscribe via email

Enter your email address:

Delivered by FeedBurner


MSDotnetMentor My Website