Glory Raj
Glory Raj

Reputation: 17691

not able to load one user control at run time in aspx page

I have got four different type of usercontorls in one page inside div one.ascx two.ascx three.ascx four.ascx

like this

<%@ Page Language="C#" MasterPageFile="~/MasterPages/template.master" AutoEventWireup="true"CodeFile="ViewCertificateMaster.aspx.cs" Inherits="Pages_ViewCertificateMaster" %>

<%@ Register Src="../Controls/one.ascx" TagPrefix="uc1" TagName="one" %>
<%@ Register Src="../Controls/two.ascx" TagPrefix="uc2" TagName="two" %>
<%@ Register Src="../Controls/three.ascx" TagPrefix="uc3" TagName="three" %>
<%@ Register Src="../Controls/four.ascx" TagPrefix="uc4" TagName="four" %>

  <asp:Content ID="Content1" ContentPlaceHolderID="phBody" Runat="Server">    
        ...... 
        ............
         ............
          some controls(button and dropdown list)

     <table border="0">
     <tr>
       <td colspan="3">
            <div class="content_grid" style="border:0px solid black;width:100%;">
              <div style="width: 100%; visibility:hidden;" runat="server" id="divViewMyCerts">
              <uc1:one runat="server" ID="one" />
                            <uc2:two runat="server" ID="two" />
                        <uc3:three runat="server" ID="three" />
                        <uc4:four runat="server" ID="four" />

                  </div>
                </div>
            </td>
       </tr>
  </table>

and then in code behind

 protected void Page_Load(object sender, EventArgs e)
 {

    if (!IsPostBack)
    {
        UserControl myAOSUsrControl = Page.LoadControl("../Controls/one.ascx") as UserControl;
        divViewMyCerts.Controls.Add(myAOSUsrControl);
        divViewMyCerts.Visible = true;
    }
 }

I am getting problem in the page load... I want load only one user control that is (one.ascx)

but I am able to see all user controls that is loaded and its taking huge amount of time to load the page because of four user controls are loaded at a time ...

This is not what I want , I want only one user control to be loaded at the page load ...

how can I solve this problem to load only one user control at a time ..... would any one have any idea how to do this, that would be very great ful to me

Many thanks in advance...

Upvotes: 0

Views: 1080

Answers (1)

Aladin Hdabe
Aladin Hdabe

Reputation: 865

First you need to remove the four user controls from your page. also remove the visibility:hidden style you can add the attribute visible="false" to the div since you set it to true in your code. Then use the code you already have but remove the !IsPostBack

<%@ Page Language="C#" MasterPageFile="~/MasterPages/template.master" AutoEventWireup="true"CodeFile="ViewCertificateMaster.aspx.cs" Inherits="Pages_ViewCertificateMaster" %>

<asp:Content ID="Content1" ContentPlaceHolderID="phBody" Runat="Server">    
    ...... 
    ............
    ............
    some controls(button and dropdown list)

    <table border="0">
    <tr>
    <td colspan="3">
        <div class="content_grid" style="border:0px solid black;width:100%;">
            <div style="width: 100%;" runat="server" id="divViewMyCerts">
            </div>
            </div>
        </td>
    </tr>
</table>

Upvotes: 1

Related Questions