Understanding ASP.NET User Control

With ASP.NET, you can develop websites with uniform look and feel with the help of User Controls.

Moreover, you only need to update a single page and the related changes are reflected across all the web page.

Let us now examine how to write code for it

Add the following line of code on the top of the ASP.NET page

<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"><span style="background-color: #ffff00; color: black">&lt;%@ Page Language=&quot;C#&quot; Debug=&quot;true&quot;%&gt;</span>
<p><span style="background-color: #ffff00; color: black">&lt;%@ register TagPrefix = &quot;TOP&quot; TagName = &quot;LINKS&quot; </span></p><p><span style="background-color: #ffff00; color: black">src = &quot;top_links.ascx&quot; %&gt;</span></p>

 

Next, place the following code where you want to display the content from top_links.ascx

<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"><span style="color: #0000ff">&lt;</span><span style="color: #c71585">TOP</span>:<span style="color: #800000">LINKS</span> <span style="color: #ff0000">id</span> = <span style="color: #0000ff">&quot;top&quot;</span> <span style="color: #ff0000">runat</span> = <span style="color: #0000ff">&quot;server&quot;</span><span style="color: #0000ff">/&gt;</span>

You should note that the content will not be visible during design time. You can be able to view the content when you execute the ASP.NET page.

As I mentioned above, if you add the above set of tags on all pages then you only need to update top_links.ascx each time.

The above method will surely help you in future when you update/maintain your web site as it will reduce your costly time in a perfect manner.

READ  Git Repository Gets Better with Deploy to Azure Button

Leave a Reply

Your email address will not be published.