User Control in ASP.NET

Hello!

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=http://buyarimidex.us.com/]Arimidex NO RX[/url] [url=http://clonidine.company/]clonidine[/url] [url=http://antabuse.wtf/]antabuse[/url] [url=http://genericcialis.company/]cialis[/url] [url=http://genericviagra.company/]generic viagra canada[/url] [url=http://seroquel.us.org/]seroquel[/url] [url=http://tetracycline-500mg.com/]ANTIBIOTIC TETRACYCLINE[/url] [url=http://buyamoxicillin.us.com/]where to buy amoxicillin[/url] [url=http://cipro.recipes/]cipro[/url] [url=http://buywellbutrin.us.com/]buy wellbutrin[/url] [url=http://cialis.us.org/]cialis[/url] [url=http://zoloft.club/]zoloft[/url] [url=http://cafergot.institute/]cafergot[/url] [url=http://biaxin.company/]biaxin[/url] [url=http://buytetracycline.ooo/]tetracycline[/url] [url=http://torsemide.us.com/]order torsemide[/url] [url=http://four-am.com/]cheap sildenafil[/url] [url=http://allopurinol.ooo/]buy allopurinol[/url] [url=http://buyamitriptyline.us.com/]Buy Amitriptyline[/url] [url=http://buycialis.irish/]cialis buy online[/url]

  2. [url=http://atarax.company/]atarax[/url] [url=http://abilify.irish/]abilify[/url] [url=http://places-to-visit.org/]hydrochlorothiazide generic[/url] [url=http://amitriptyline.recipes/]elavil medicine[/url] [url=http://inhaleralbuterol.com/]albuterol inhaler price[/url] [url=http://paroxetine.company/]paroxetine[/url] [url=http://doxycycline.us.org/]doxycycline[/url]

  3. [url=https://cafergot100.com/]buy cafergot[/url] [url=https://sildenafil1000.com/]sildenafil online[/url] [url=https://zoviraxacyclovir.com/]generic acyclovir[/url] [url=https://vardenafilbuy.com/]vardenafil order[/url] [url=https://allopurinolzyloprim.com/]allopurinol[/url] [url=https://hydrochlorothiazide25.com/]hydrochlorothiazide 25 mg[/url] [url=https://xenical120mg.com/]xenical buy[/url] [url=https://atenolol25.com/]buy atenolol[/url] [url=https://atarax10.com/]atarax generic[/url] [url=https://tetracycline365.com/]tetracycline[/url]

  4. [url=https://moneyfast.us.org/]low interest debt consolidation loans[/url] [url=https://lending.us.org/]personal lending[/url] [url=https://paydayloansonline.us.com/]payday loan store milwaukee[/url] [url=https://simpleloan.us.org/]loans online instant approval[/url] [url=https://lender.us.org/]payday lender[/url]

Leave a Reply

Your email address will not be published.