views:

385

answers:

2

Hello

I have created one aspx Page from that i need to access the property of Usercontrol.

Note : User control not registerd in a page, Its loaded Dynamically by using Loadcontrol.

Even i am wondering while i am typing Excact Class Name of User control, it can not be resolved. Then how can i create Object for user control.. without accessing Public class Can you please help me.

Thanks in Advance.

+2  A: 
Control c = LoadControl("~/Sample.ascx");
form1.Controls.Add(c);

EDIT: Registered user control's class name can used,

<%@ Register src="Sample.ascx" tagname="Sample" tagprefix="uc1" %>

CODE:

Sample c =(Sample) LoadControl("~/Sample.ascx");
c.SomeProperty="value";
form1.Controls.Add(c);
adatapost
I dont want to register with in a aspx page, to reduce Overload of Page, Help?
karthik
You should plan to create a custom control.
adatapost
A: 

see following link to desing custom controls

http://msdn.microsoft.com/en-us/library/zt27tfhy.aspx

alternatively, if you dont want to register within aspx page, you can register globally in web.config

<system.web>
    <pages>
      <controls>
        <add assembly="My.Web.Controls"
                namespace="My.Web.Controls"
                tagPrefix="st" />
        <add src="~/Controls/MyControl.ascx"
                tagName="UserControl"
                tagPrefix="uc" />
      </controls>
    </pages>
</system.web>
Saar