Top Banner
Tutorial How to use User Web Controls Justin Chua P1032215
7

User Web Control in ASP

Apr 07, 2018

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: User Web Control in ASP

8/6/2019 User Web Control in ASP

http://slidepdf.com/reader/full/user-web-control-in-asp 1/7

Tutorial

How to use User Web Controls

Justin Chua

P1032215

Page 2: User Web Control in ASP

8/6/2019 User Web Control in ASP

http://slidepdf.com/reader/full/user-web-control-in-asp 2/7

U ser Web Control in ASP.Net

The user web control in ASP.net is a simple user interface that is similar to a webform function, but instead,

this is just one of the smaller control groups.

Notice the facebook buttons at the top? No matter which part of the website you are at, you will still be able

to see the three buttons. Those are what is known as U ser Web Controls . In this tutorial, I will teach you how

to create a simple user web control, and also how to implement them.

Step 1: Create a new web site

And name it testWeb U serControl

Create a new folder, called Action .

Page 3: User Web Control in ASP

8/6/2019 User Web Control in ASP

http://slidepdf.com/reader/full/user-web-control-in-asp 3/7

The folder is where the Web U ser control will be stored at.

Everytime we need to use the web control, we will need to call it at the top of the web page (Examples later)

After that, add a new Item (Web U ser Control) , the extension is .ascx

Once created, you will have noticed something different. This is similar to a Web Page, (aspx) file, but just that

in this form, we do not have the respective HTML tags (It can still be implemented)

Enter the codes inside

<table border ="1"> < tr> < td > <asp :Labelrunat ="server" Text="Testing Label"></ asp :Label></ td > < td > <asp :TextBoxrunat ="server" ID="txtTest"></ asp :TextBox></ td > </ tr> < tr>

< td><asp:Label runat=µserverµ Text =µµ ID=µlblTestµ></asp:Label> </ td > < td > <asp :Button ID="btnTest" runat ="server" Text="Test"/></ td ></ tr></ table >

Page 4: User Web Control in ASP

8/6/2019 User Web Control in ASP

http://slidepdf.com/reader/full/user-web-control-in-asp 4/7

This creates a simple table in the form, as such

U nder the code behind file (Right click > View Code)

Enter the following codes for your button click event handler.

Now we will be implementing the logic inside the table.

A simple test would be, in that empty label, we show what we have typed in the text field.

PartialClass ExperimentTest Inherits System.Web.UI. UserControl

ProtectedSub btnTest_Click( ByVal sender AsObject , ByVal e As System. EventArgs ) Handles btnTest.ClickDim testString AsString = txtTest.Text

lblTest.Text = testString

EndSub EndClass

Page 5: User Web Control in ASP

8/6/2019 User Web Control in ASP

http://slidepdf.com/reader/full/user-web-control-in-asp 5/7

Now we ve done creating a very simple web user control. Let s try to implement it.

Get a new web form (NOT INSIDE ACTION FOLDER)

Now, go to the aspx page (NOT the code behind file), enter this line

Page 6: User Web Control in ASP

8/6/2019 User Web Control in ASP

http://slidepdf.com/reader/full/user-web-control-in-asp 6/7

Page 7: User Web Control in ASP

8/6/2019 User Web Control in ASP

http://slidepdf.com/reader/full/user-web-control-in-asp 7/7

Why is this user web control useful?

This use web control can be implemented in many ways, for example, you can do a Search function using a

user web control.

For example, from one particular video renting area, we can use a gridview web user control to databind the

various categories in.

Each of the hyperlinks actually links to the various categories, where the movies are sorted into different

categories.

And the code-behind file isn t really long, it s just similar to a normal web form, using those classes, and the

functions to get values to databind into the gridview.