All server side controls are ASP.Net controls, provide events for writing server side code. As a user, we choose these events and write C# code using .Net Libraries and ASP.Net objects.
Because ASP.Net controls are processed at server, their code is also executed when user submits the form to server. for any reason client fails to submit the form then server side code i.e., ASP.Net code will not be executed.
Example: Let's look at this simple example.
Because ASP.Net controls are processed at server, their code is also executed when user submits the form to server. for any reason client fails to submit the form then server side code i.e., ASP.Net code will not be executed.
Example: Let's look at this simple example.
- Design the form as following
- Coding
Under Button Click Event: //Server side code
TextBox1.Text = "Welcome";
Under CheckBox CheckedChanged:
TextBox2.Text = "I'm a CheckBox";
Under ListBox SelectedIndexChanged:
TextBox3.Text = "Course Changed";
From this demo, we can clearly understand the behaviours of ASP.Net controls when the form is submitted.
OK! Let's see one more Example of this kind with one important Property - "AutoPostBack"
Example:
//Enable "AutoPostBack" property for CheckBox.
- Coding
Under CheckBox CheckedChanged:
if(CheckBox1.Checked)
Label2.Text = TextBox1.Text + " is Employed ";
else
Label2.Text = TextBox1.Text + " is not Employed ";
AutoPostBack:
This property enables the Post back behavior of ASP.Net controls suck as CheckBox, RadioButton etc., This property is by default enable for controls like Button, LinkButton, ImageButton etc.,
Well! hope you understood how to work with ASP.Net Controls. Try yourself the following requirement.
- when user enters name and check the employee and click on submit then Label should be "[Username] is Employed" and also if he check the domains(.Net / Java) then it should be "[Username] is Employed in [Domain]".
- If he selects domain and submit without selecting Emplyed then it should be "[Username] is not Employed"
----------------------------------------------------------
** If you like this post please like our page in facebook
" Dot Net Support" .
0 comments:
Post a Comment