hello dear asp.net instructor.
i'm just started asp.net and i have a little background on object oriented programming in c#.
my question is: why can't we use "m1 = new mywc()" instead of " m1=(mywc)LoadControl("~/mywc.ascx" ) ".
thank you for your nice tutorial.
i'm just started asp.net and i have a little background on object oriented programming in c#.
my question is: why can't we use "m1 = new mywc()" instead of " m1=(mywc)LoadControl("~/mywc.ascx" ) ".
thank you for your nice tutorial.
Hi,
Try using the Reference declaration on your page:
Now you should be able to use the type from your Code Behind file. I'm not sure if you can instantiate it like any other type, with the new operator, or if you have to use the LoadControl method and then typecast to your type when you want to use specific members on your UserControl. Try it and let me know
Try using the Reference declaration on your page:
<%@ Reference Control="~/MyUserControls/MyControl.ascx" %>
Now you should be able to use the type from your Code Behind file. I'm not sure if you can instantiate it like any other type, with the new operator, or if you have to use the LoadControl method and then typecast to your type when you want to use specific members on your UserControl. Try it and let me know

Hello webmaster,
is there possibly the CodeBehind file in its final finished form for us to look at somewhere?
I was making it ok in the tutorial until i got to this page:
http://asp.net-tutorials.com/user-controls/using/
protected void Page_Load(object sender, EventArgs e)
{
// These values can come from anywhere, but right now, we just hardcode them
MyUserInfoBoxControl.UserName = "Jane Doe";
MyUserInfoBoxControl.UserAge = 33;
MyUserInfoBoxControl.UserCountry = "Germany";
}
the above is causing the dreaded "Error 3 Expected class, delegate, enum, interface, or struct"
phUserInfoBox.Controls.Add(LoadControl("~/UserInfoBoxControl.ascx"));
It's unclear where exactly in the CodeBehind to put the above snippet.
Yes, i'm an ASP newbie.
Thanks in advance!
is there possibly the CodeBehind file in its final finished form for us to look at somewhere?
I was making it ok in the tutorial until i got to this page:
http://asp.net-tutorials.com/user-controls/using/
protected void Page_Load(object sender, EventArgs e)
{
// These values can come from anywhere, but right now, we just hardcode them
MyUserInfoBoxControl.UserName = "Jane Doe";
MyUserInfoBoxControl.UserAge = 33;
MyUserInfoBoxControl.UserCountry = "Germany";
}
the above is causing the dreaded "Error 3 Expected class, delegate, enum, interface, or struct"
phUserInfoBox.Controls.Add(LoadControl("~/UserInfoBoxControl.ascx"));
It's unclear where exactly in the CodeBehind to put the above snippet.
Yes, i'm an ASP newbie.
Thanks in advance!

Hi Owl,
A more complete example would look something like this:
The BlahBlah part should be changed to the name of your current class
A more complete example would look something like this:
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class BlahBlah : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//Page_Load code here
}
}
The BlahBlah part should be changed to the name of your current class
