-
Play Item
How to Add Event Handler Method to Command Button
By 5minLearn how to add Event Handler in command button on…
-
Play Item
How to Add Another Event Handler Method
By 5minLearn how to install an Event Handler on other Command…
-
Play Item
How to Work With the TextChanged Event Handler in ASP.NET
By 5minLearn how to work with the TextChanged Event Handler.
-
Play Item
How to Add an Event Handler to a Button in ASP.NET
By 5minLearn how to add an Event Handler to a command…
-
Play Item
How to Make a Roasted Turkey
in American CookingIn this great food video get ready for the holidays and learn…
-
Play Item
Five Things for the Family in Miami
in AmericasHere are five things for the family in Miami, Florida
-
Play Item
Upgrading from Windows XP to Windows 7 #2 - Pros and Cons of Dual Booting
in SoftwareAs you can't do a direct upgrade from Windows XP to Windows…
-
Play Item
How to get Sales on the Internet
in GeneralLearn how Internet marketer Frank Furness shares strategies for business on how…
How to Add Event Handler and Logical Code in ASP.NET
More DIY videos at 5min.com
Video Summary:
Learn how to add Event Handler and Logical Code in ASP.NET.
Video Tags:
aspnet event handler, web control class, visual studio 2005, Microsoft Windows, web development, total training
Source: How to Add Event Handler and Logical Code in ASP.NET
Video Transcript: (More)
Okay. Now if I wanted to, I could right click on that control and I could set the styles so I’ll just click that. And this is the Style Builder dialogue box that we saw earlier when we look at HTML controls and I could use the same approach if I wanted to here, to set the visual appearance for my web control and that is fine. I am not going to do that. I will cancel the window and instead we will come back to the properties window in the bottom corner and you can see that we have higher level controls that you can set individually, so this gives you a richer programming model. You do not have to set styles at the HTML level. What we do in here is we are setting properties on that .net class and it will in turn render the appropriate style attribute in the HTML when it gets return back to the browser. So for example, let us set the background color to be a web color and we will go for, let me see dark orange appeals to me and we will set the font properties. We will set the foreground color for the font to be, how about maroon? Could it work? And finally on the font item, we will set the font names to be, well let us choose some fonts. We can choose Arial because I preferred that font and then I will press enter and then we could choose Verdana as our next preferred font and then finally we could choose San-Serif as the full back front. I will click Ok.
So, that is the different way for setting attributes on the asp label. We use high level properties instead of setting the low level styles like we did with the HTML control, very good!
Last thing we need to do is to add the button so, let us add the button onto our web page and drag it there. We will set the ID of the button to be “Submit Button”. And we will set the text to be “Submit” okay and we are done. Now then, let us think about how we are going to handle the click event on this button. If you recall how we handled it on the HTML button, we had to manually go into the Source View and then we have to add in here the On Server Click event. And we have to manually then go into the code; type in a method with the correct signature and that was a quite a time consuming error-prone process. We do not need to do any of that when we are using web controls because it is a web control, it has a high level event that I can access via the property window. So, let us just do that. Let us go back to the design view, click our button and then over in the property window, here is our lightning bolt which shows the events for the control.
Now, you can handle any of these events if you want to. Most often, you will just handle a click event. If you double click on the event name, it will add a method with a default name such as Submitbutton_Click. So, let us do that. I am going to double click an event name and it has added the event handler method here. So, all we need to do now is to write some code to gather the users data and display it in the Result label. Okay, so let us do that. I am going to declare a string variable called “Name” and that is going to capture the name entered in the NameTextbox. And we will also capture the user’s age. So, this is by similar to before but if you remember, when we are dealing with HTML controls, the property that we are accessing was called value but now that we are using asp.net text boxes, the value of the property that we are





No comments yet.