Home » Asp.netRSS

adding windows user control in asp.net application

hi fri i had created one user control in c# and i want to add this user control in asp.net application pl tel me how to do this


thanks in advance

 

1 Answer Found

 

Answer 1

You need to register your UserControl in the page where you are consuming it as per the following:

 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ Register Src="WebUserControl.ascx" TagName="WebUserControl" TagPrefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <uc1:WebUserControl ID="WebUserControl1" runat="server" />
    </div>
    </form>
</body>
</html>


Or if you want to load it dynamically use the following:

<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>

 

Control ctrl = LoadControl("UserControlPath");

PlaceHolder1.Controls.Add(ctrl);

Please read the following articles:

http://webproject.scottgu.com/CSharp/UserControls/UserControls.aspx

http://www.codersource.net/asp-net/asp-net-advanced/creating-a-web-user-control-in-c.aspx

 
 
 

<< Previous      Next >>


Microsoft   |   Windows   |   Visual Studio   |   Follow us on Twitter