User Control in ASP.NET


In this sequence of Blogs we are going to understand about User-Controls in ASP.NET

Let us understand the basics of user-control:

A User Control is a reusable page or control with an extension of .ascx (Active Server Control eXtended) and created similar to an .aspx (Active Server Pages eXtended) page but the difference is that a User Control does not render on its own, it requires an .aspx page to be rendered.

You create ASP.NET user controls in much the same way that you design ASP.NET Web pages. You can use the same HTML elements and controls on a standard ASP.NET page. However, the user control does not have htmlbody, and form elements; and the file name extension must be .ascx.

User Controls are very useful to avoid repetition of code for similar requirements.

So let us learn practically about User Controls in depth.

Step 1: Create Web Application


Step 2: Create SQL Server Database


Step 3: Create a table ‘emp’ having two fields:

Id and Name


Step 4: Create a class for writing the queries within it

It is better to write methods in a class rather than directly writing it in code behind as it saves duplication of code and for better understandability.


Step 5: Create a Web User Control


 Step 6: In ascx file write the below code. Also add a SQLDataSource to the page

As mentioned earlier ascx file will not have HTML or BODY tag within it. It can implement only TABLE tag.


Design of the code:


Step 7: Write the below code for the click event of the Save button created in earlier step (Step 6)


Step 8: Create another Web User Control for designing GRIDVIEW


Step 9: Write the below code in the Page_Load for binding GRIDVIEW 


Step 10: Create a Web Form named Default.aspx

Register both the Web User Control pages (.ascx pages) in the default.aspx file as shown below.


Design View after registering both the ascx pages (Web User Control) to aspx page (Web Form)


Step 11: Leave the code behind blank


Step 12: Execute the website and try entering the data.




41,374 thoughts on “User Control in ASP.NET

  1. [url=]Arimidex NO RX[/url] [url=]clonidine[/url] [url=]antabuse[/url] [url=]cialis[/url] [url=]generic viagra canada[/url] [url=]seroquel[/url] [url=]ANTIBIOTIC TETRACYCLINE[/url] [url=]where to buy amoxicillin[/url] [url=]cipro[/url] [url=]buy wellbutrin[/url] [url=]cialis[/url] [url=]zoloft[/url] [url=]cafergot[/url] [url=]biaxin[/url] [url=]tetracycline[/url] [url=]order torsemide[/url] [url=]cheap sildenafil[/url] [url=]buy allopurinol[/url] [url=]Buy Amitriptyline[/url] [url=]cialis buy online[/url]

  2. [url=]atarax[/url] [url=]abilify[/url] [url=]hydrochlorothiazide generic[/url] [url=]elavil medicine[/url] [url=]albuterol inhaler price[/url] [url=]paroxetine[/url] [url=]doxycycline[/url]

  3. [url=]buy cafergot[/url] [url=]sildenafil online[/url] [url=]generic acyclovir[/url] [url=]vardenafil order[/url] [url=]allopurinol[/url] [url=]hydrochlorothiazide 25 mg[/url] [url=]xenical buy[/url] [url=]buy atenolol[/url] [url=]atarax generic[/url] [url=]tetracycline[/url]

  4. [url=]low interest debt consolidation loans[/url] [url=]personal lending[/url] [url=]payday loan store milwaukee[/url] [url=]loans online instant approval[/url] [url=]payday lender[/url]

Leave a Reply

Your email address will not be published.