add user control in classic asp file

Posted by Venkatesh under ASP.NET on 11/16/2012 | Points: 10 | Views : 2801 | Status : [Member] | Replies : 1

I have classic asp file in that file i want to add my usercontrol . Is there any way to add that control please give me reply.



Posted by: Sandhyab on: 11/16/2012 [Member] Starter | Points: 25


User control allows us to build a new control by using existing controls. It is very frequently used in the scenario where you need to reuse the code or certain bunch of controls in multiple pages (eg. Menus, category list etc.).
Right click the project and select "Web User Control" (.ascx file)
Then In Your aspx page use this directive
<%@ Register Src="~/YourUsercontrol.ascx" TagPrefix="uc1" TagName="Menu" %>

Once try below code

ASCX PAGE (USER CONTROL) (This is web user control)
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="MenuControl.ascx.cs" Inherits="MenuControl" %>

<div style="background-color:#f0f0f0;padding:5px;">
<a href="Default.aspx" title="Home">Home</a> | <a href="Page1.aspx" title="Page 1">Page 1</a> | <a href="Page2.aspx" title="Page 2">Page 2</a>
<hr /></div>

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Copy of Default.aspx.cs" Inherits="_Default" %> <%@ Register Src="~/MenuControl.ascx" TagPrefix="uc1" TagName="Menu" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head runat="server">
<form id="form1" runat="server">
<uc1:Menu runat="server" ID="Menu1" />
<h1>Page 1</h1>

Thanks & Regards

Venkatesh, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response