
<table align="center">
<tr>
<td colspan="2">
<asp:Label ID="lblusername"
runat="server"
ForeColor="Red"></asp:Label>
</td>
</tr>
<tr>
<td>
UserName:
</td>
<td>
<asp:TextBox ID="txtusername"
runat="server"></asp:TextBox><asp:RequiredFieldValidator
ID="RequiredFieldValidator1"
runat="server"
ControlToValidate="txtusername">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Button ID="btnSaveName"
runat="server"
Text="Save"
OnClick="btnSaveName_Click"
style="height: 26px" />
</td>
</tr>
</table>
In Userinformation.ascx.cs file add the code like this.
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Linq;
public partial class UserControl_UserInformation
: System.Web.UI.UserControl
{
protected void
Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
}
}
protected void
btnSaveName_Click(object sender, EventArgs e)
{
InsertData();
Response.Redirect("~/Default.aspx");
}
private void
InsertData()
{
Userinfo info = new
Userinfo();
info.UserName =
txtusername.Text.Trim();
using (UserInformationDataContext
db = new UserInformationDataContext())
{
try
{
db.Userinfos.InsertOnSubmit(info);
db.SubmitChanges();
}
catch (Exception
ex)
{
Response.Write("Error:" +
ex.Message);
}
}
}
}
Step 3: Add the code in UserInformationGrid.ascx.
<%@ Control Language="C#"
AutoEventWireup="true"
CodeFile="UserInformationGrid.ascx.cs"
Inherits="UserControl_UserInformationGrid"
%>
<asp:GridView ID="GridView1"
runat="server"
AllowPaging="True"
AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="ID"
HeaderText="ID"
/>
<asp:BoundField DataField="UserName"
HeaderText="UserName"
/>
</Columns>


SubashPosted Mar 16, 2017, 8:49 PM
Thank you sir nice one
Rakesh reddyPosted Jan 30, 2017, 9:42 PM
Very helpful article, Thank you sir
Muhammad Aqib ShehzadPosted Jul 20, 2016, 8:59 AM
Very nice
kalu singh raoPosted Jul 20, 2016, 8:53 AM
Nice one...
Gowtham RajamanickamPosted Apr 7, 2016, 3:01 AM
good one..good one..
Ajay KadamPosted Jan 16, 2016, 7:44 AM
Thanks sir
Manoj KallaPosted Dec 12, 2015, 6:57 AM
Nice
Jaipal ReddyPosted May 25, 2015, 6:38 AM
Nice and needful article. thnak you
priya gokulaPosted Jan 3, 2015, 7:54 AM
sir, .ascx file support nested repeater button
Ritesh SinghPosted Jul 10, 2014, 4:44 AM
thankuuu
anjali dPosted Apr 21, 2014, 5:57 AM
very helpful artical thanks
sunil guptaPosted Sep 22, 2013, 2:32 PM
hi sir how to include UserInfo and UserInformationDataContext
Atiullah SiddiquePosted Aug 25, 2013, 4:59 AM
hi sir user control working in local host but not in server
Amruta UdgiriPosted May 9, 2013, 3:06 AM
thank u sir..
dipika sharmaPosted Jun 22, 2012, 3:19 AM
thank u sir...........
dipika sharmaPosted Jun 22, 2012, 3:19 AM
thank u sir...........
Praveen SinhaPosted Feb 8, 2012, 1:40 AM
Hi sir can we make .ddl file of that user control so that we can use anywhere and any application. If it is possible then what is the process.kindly inform me. thanx praveen [email protected]
Ramu KondaruPosted Aug 6, 2011, 8:42 AM
Thank You Sir