HOW TO CREATE WEBUSER CONTROL
VISUAL STUDIO->SOLUTION EXPLORE->ADD NEW ITEM->WEBUSERCONTROL
WEBUSERCONTROL EXTENSTION--ASCX
Webusercontrol.ascx
<%@ Control
Language="C#"
AutoEventWireup="true"
CodeBehind="WebUserControl1.ascx.cs"
Inherits="usercontrol.WebUserControl1"
%>
<table>
<tr><td><asp:Label ID="labname1" runat="server" Text="Name"></asp:Label></td><td>:</td><td><asp:TextBox ID="txtname1" runat="server" ></asp:TextBox></td></tr>
<tr><td><asp:Label ID="labsal" runat="server" Text="Salary"></asp:Label></td><td>:</td><td><asp:TextBox ID="txtsal" runat="server" ></asp:TextBox></td></tr>
<tr><td></td><td></td><td><asp:Button ID="btemp" runat="server" Text="save"
onclick="btemp_Click"
/></td></tr>
</table>
<asp:TextBox ID="txtname" runat="server"></asp:TextBox>
<asp:Button ID="bt" runat="server" Text="Check" onclick="bt_Click" />
</br>
<asp:Label ID="labname" runat="server" ></asp:Label>
Webusercontrol.ascx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
namespace usercontrol
{
public partial class WebUserControl1
: System.Web.UI.UserControl
{
SqlConnection con = new
SqlConnection("Data
Source=INTEGRIT-EEAF88\\SQLEXPRESS;Initial Catalog=aravindh;Integrated
Security=True");
protected void Page_Load(object sender, EventArgs
e)
{
}
protected void
bt_Click(object sender, EventArgs e)
{
labname.Text = txtname.Text.ToString();
}
protected void
btemp_Click(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd = new
SqlCommand("insert
into employee values('" + txtname1.Text + "','"
+ txtsal.Text + "')", con);
cmd.ExecuteNonQuery();
con.Close();
}
}
}
VISUAL STUDIO->SOLUTION EXPLORE->ADD NEW ITEM->WEBFORM(DEFAULT.ASPX)
Default.aspx
<%@ Page
Language="C#"
AutoEventWireup="true"
CodeBehind="test.aspx.cs"
Inherits="usercontrol.test"
%>
ADD REGISTER IN WEBUSER CONTROL
SRC ==WEPUSERCONTROL PAGE
TAGNAME AND TAGPREFIX(YOU CREATE THIS NAME CALL FOR THIS CONTROL)
<%@ Register
Src="WebUserControl1.ascx"
TagName="usercontrol1"
TagPrefix="ucl"
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD
XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<ucl:usercontrol1 runat="server"
id="uc"></ucl:usercontrol1>
</div>
</form>
</body>
</html>
SQL TABLE:
SQL TABLE:
Create table employee(name varchar(30),salary varchar(30))