WebUserControl.ascs
<%@ Control Language="C#" AutoEventWireup="true"
CodeBehind="WebUserControl.ascx.cs" Inherits="MyUserControl.WebUserControl" %>
<h3>This is User Control </h3>
<table>
<tr>
<td>Name</td>
<td> <asp:TextBox ID="txtName" runat="server"></asp:TextBox> </td>
</tr>
<tr> <td>City</td>
<td><asp:TextBox ID="txtcity" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td>
<asp:Button ID="txtSave" runat="server" Text="Save" onclick="txtSave_Click" /> </td>
</tr>
</table><br />
<asp:Label ID="Label1" runat="server" Text=" "></asp:Label>
WebUserControl.ascs.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace MyUserControl
{
public partial class WebUserControl : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void txtSave_Click(object sender, EventArgs e)
{
Label1.Text = "Your Name is " + txtName.Text + " and you are from " + txtcity.Text;
}
}
}
Usercontrol.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="UserControl.aspx.cs"
Inherits="MyUserControl.UserControl" %>
<%@ Register Src="WebUserControl.ascx" TagPrefix="uc" TagName="Student"%>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
</head> <body>
<form id="form1" runat="server">
<div>
<uc:Student ID="studentcontrol" runat="server" />
</div>
</form>
</body>
</html>
0 Comments