1

I have an Asp.net Website in which there's a user control(uc_cart.ascx) and a webpage(checkout.aspx), I want to create an object of uc_cart.ascx in checkout.aspx but I can't do this it simply doesn't shows up in intellisence box, But when I do same thing in Web Application I can.

After a while I noticed that I have to register that UC in my webpage using <%@ Register %> , only after that I can access that class and can create an object of the same in Website but in Web Applications I don't have to do that.

So basically what are the major differences between a Website and a Web Application ?

and Why can't I create that object with out that<%@ Register %> block ?

yogi
  • 19,175
  • 13
  • 62
  • 92

1 Answers1

1

Use LoadControl method to instantiate the Web User control.

Control control=LoadControl("~/uc_cart.ascx");
PlaceHolder1.Controls.Add(control);

Reference Links:

  1. MSDN - Web Application Projects versus Web Site Projects in Visual Studio
  2. StackOverflow - ASP.NET: Web Site or Web Application?
Community
  • 1
  • 1
KV Prajapati
  • 93,659
  • 19
  • 148
  • 186
  • My requirements were a little different, But question isn't about how can I create that object question is WHY I can't with out that `<%@ Register %>` ? – yogi Oct 03 '12 at 12:29
  • 1
    @yogi - No need to `<%@ Register %>` a control if you're creating a control dynamically using `LoadControl` method. – KV Prajapati Oct 03 '12 at 12:31
  • Actually I was finding that control in Master page and creating an object of that control in my webpage, But I guess the code that you have provided will create a new object of that control. What should I do in this case ? – yogi Oct 03 '12 at 12:35