-
ASP.NET - C# - Dynamic text image control
By CodeGolemMany programmers already use GDI functionalities to dynamically render images…
-
ASP.NET - C# - Using UserControls as Mail Templates
By CodeGolemHere I will propose a way to use UserControls as…
-
Intro to Information Systems Final Review
By DanimalMonsterNotes I took for my business IS and QS class…
-
Ins and Outs of Custom Web Applications
By andra33Custom web applications are some of the most popular web…
-
Play Item
How to Use the throwing Stick Part 1/2
in GeneralHedgehogLeatherworksHow to Use the throwing Stick Part 1/2
-
Play Item
How to Perform the Matrix Yo-Yo Trick
in GeneralLearn how to perform great Yo-Yo tricks, this video tutorial will show…
-
Play Item
Strange Interesting Facts 3, Hot Facts & Fun Girls
in GeneralStrange Interesting Facts 3, Hot Facts & Fun Girls Strange World Interesting…
-
Play Item
Pot your Plants - Placing Plants in the Container
in Gardening & LandscapingIn this video, Mitch demonstrates how to create a container garden including…
How to Invoke the Run As Server Control Function
More DIY videos at 5min.com
Video Summary:
Learn how to Invoke the Run As Server Control Function in ASP.NET.
Video Tags:
server control, html control class, visual studio 2005, Microsoft Windows, web development, total training
Source: How to Invoke the Run As Server Control Function
Video Transcript: (More)
So if the age control for that textbox, let us say Run as Server Control for the label, right click and say “Run As Server Control” and then for each of the checkboxes, I will select all the checkboxes and then I am going to run them all as server controls. Finally, let us not forget the button itself. Right click the button and then Run As Server Control. So, what is the purpose of doing that? What that means is when we submit the data to the asp.net web server, each item that is specified as runat=server will be represented by a .net object in my server application which will expose the data and enable me to interact with the object in the easier way than using traditional asp processing techniques. Hopefully, all of this will become clear in a moment when we are asked to implement the event handler for the Submit button. Let us click on the Submit button again and come down to the properties window and set event. You will notice that there is no event button here but we look at how to do this with web control in lesson one. There is a little lightning bolt here which specifies the various different events you could handle on that control.
Unfortunately, when you are using html controls such as Submit buttons and Input textboxes, you do not get any events displayed in the property window. What you have to do and probably guessed this by now is going to the source view and manually add the event handling attribute yourself. So, I am going to locate the Submit button, here it is. There are two types of server event that you can handle for html controls. One is server click and the other is server change. So for button, we need to handle the on server click event and you need to give it a name of a method and the code behind the class which will handle the event. So, I am going to choose the name, “MySubmitHandler” and I am going to implement that method in a moment. Let us go to the code behind class and here we are going to have to manually add an event handler called MySubmitHandler. You have to be quite accurate here. So the method is going to be protected and it has no return value, so void. We set the name of the method was MySubmitHandler. The arguments for the method must be exactly as I am going to type here. So the first parameter is an object and that represents the sender or the control that generated the event. In other words, the button and the second parameter must be an EventArgs and I will call that parameter args. In this method, I am going to implement my event handler logic for the Submit button. So, the first thing that I am going to do is I am going to retrieve the user’s name. So, I am going to declare a string variable called “Name” and I am going to retrieve the value from the name textbox.
So, Name Textbox is an object which is available to my code at the server and it is available because in my aspx page, when we specified the textbox, we indicated that the textbox is runat server. And, because of this runat server, that tells asp.net that when the web application runs, it should create an object with the same name, Name Textbox and make that object available to us in our code. So this here is present purely because of the runat equal server attribute. That is a very important point for you to understand.
Okay, so that is the person’s name. Let us also get the person’s age. And what we will do next is we will get the person’s nationality. So string nationality equals, now if you remember, the select control was called nationality l





No comments yet.