Hi all,

I have a masterpage and contentPlaceHolder in it. I used <asp:content .. in Default aspx. I have web user controls.
By sending parameter to Default.aspx, can I call different web user controls in Default aspx.
I try to that because of not making a page same with Default.aspx for every web user control.

I have an idea about that, but is that possible ?? :

in default.aspx :

<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" Title="HomePage" Async="true"%>
<%@ Register TagPrefix="pnl" TagName="SmartPanelButton" Src="~/SectionControls/Panel/PanelControl.ascx" %>
<%@ Register TagPrefix="lgn" TagName="LoginControl" Src="~/SectionControls/Login/LoginControl.ascx" %>

<asp:Content ID="MainContent" ContentPlaceHolderID="MainContent" runat="server">
    <div id="divMainContent" >
        <lgn:LoginControl ID="LoginControl" runat="server" />
    </div>
</asp:Content>

Can I change type(lgn:LoginControl) of "LoginControl" codebehind while page initiliaze? IF it is possible, I can register the page to this web user control depending on parameters come from previous page and load it.

I mean : (codebehind)

if(parameter = 1) register page with TagPrefix="usr" TagName="ProfilControl" Src="~/SectionControls/Profil/Profil.ascx"

else if(parameter==2) register page with TagPrefix ....

is there a way for that ??

thanks for all helps and ideas.
Deniz

i think you want to add web user controls dynamically. it can be done this way :

in the page load event of your default page add this :

void Page_Load(object sender, EventArgs e)
{

if(your case)
  {
  form1.Controls.Add(LoadControl("WebUserControl.ascx"));
  }

}

I don't think it is possible to dynamically register a control on a page. Why not register each control type that might be included? The overhead from this is pretty small. Then you can use serkansendur's code to add a control of whatever type is registered, and Form.Controls.Remove(id) to remove the control you are replacing.

This article has been dead for over six months. Start a new discussion instead.