Hi There,
I tried what you suggested. This is my complete code on the page
using System;
using System.Collecti ons;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.Sess ionState;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.H tmlControls;
using AgogeNet.COM;
using AgogeNet.UserCo ntrols.ISJob;
namespace AgogeNet.ISJob
{
/// <summary>
/// Summary description for _default.
/// </summary>
public class _default : System.Web.UI.P age
{
protected System.Web.UI.H tmlControls.Htm lForm logout;
protected Microsoft.Web.U I.WebControls.T abStrip TabISJob;
protected Microsoft.Web.U I.WebControls.M ultiPage mpISJob;
protected System.Web.UI.W ebControls.Link Button lbtnLogout;
protected System.Web.UI.W ebControls.Plac eHolder plhISAdmin;
protected System.Web.UI.W ebControls.Butt on Submit;
protected System.Web.UI.W ebControls.Plac eHolder plhISGeneral;
private void Page_Load(objec t sender, System.EventArg s e)
{
// Put user code to initialize the page here
//loading one of the controls dynamically
//and placing it in a placeholder
if(!Page.IsPost Back)
{
string UserRole = Session["UserRole"].ToString();
if (UserRole == "IS Administrator")
{
uctlJobGeneral UC1 =
(uctlJobGeneral )LoadControl(". ./UserControls/ISJob/uctlJobGeneral. ascx");
plhISGeneral.Co ntrols.Add(UC1) ;
uctlJobAdmin UC =
(uctlJobAdmin)L oadControl("../UserControls/ISJob/uctlJobAdmin.as cx");
plhISAdmin.Cont rols.Add(UC);
}
else
{
System.Web.UI.C ontrol UC1 =
Page.LoadContro l("../UserControls/ISJob/uctlJobGeneral. ascx");
plhISGeneral.Co ntrols.Add(UC1) ;
}
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArg s e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeCompo nent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.Submit.Cli ck += new System.EventHan dler(this.Submi t_Click);
this.Load += new System.EventHan dler(this.Page_ Load);
}
#endregion
private void Submit_Click(ob ject sender, System.EventArg s e)
{
string JobType = UC1.JobTypeValu e.ToString();
}
}
}
When I try to run the website it gives me an error saying that UC1 is not
defined.
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
You need to cast the controls to their appropriate type, else they are
just Controls and only expose Control properties and methods.
if ur uctlJobGeneral. ascs looks like:
public class JobGeneral : UserControl
{
}
you could do
JobGeneral UC1 =
(JobGeneral)Loa dControl("../UserControls/ISJob/uctlJobGeneral. ascx");
Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/
http://openmymind.net/redirector.aspx?documentId=51 - Learn about AJAX!
"Vivek Sharma" <vi********@hot mail.com> wrote in message
news:uH******** *****@TK2MSFTNG P15.phx.gbl... Hi There,
I have a situation where I wish to load the controls dynamically on the
basis of user role. Hence, I am using this code.
if (UserRole == "IS Administrator")
{
Control UC1 =
LoadControl("../UserControls/ISJob/uctlJobGeneral. ascx");
plhISGeneral.Co ntrols.Add(UC1) ;
System.Web.UI.C ontrol UC =
Page.LoadContro l("../UserControls/ISJob/uctlJobAdmin.as cx");
plhISAdmin.Cont rols.Add(UC);
}
else
{
System.Web.UI.C ontrol UC1 =
Page.LoadContro l("../UserControls/ISJob/uctlJobGeneral. ascx");
plhISGeneral.Co ntrols.Add(UC1) ;
}
My problem is on the click of the button (which is not included within
the control) I am unable to access the properties of the user controls.
How can I access the properties?
Please help.
Viverk