Groups | Blog | Home
all groups > asp.net > february 2004 >

asp.net : User controls



Raterus
2/25/2004 5:32:55 PM
I think you are making it more difficult that it needs to be. It the =
usercontrol's class, declare a public variable "myText"

in page_load of the webcontrol, or whereever else you want it, set =
myTextBox.text =3D myText

then when you use the control in your aspx, do this

<uc1:WebUserControl1 id=3D"blah" runat=3D"server" myText=3D"Text to see =
in UserControl">

Hope this helps,
--Michael
[quoted text, click to view]

In a test project, I have created two WebForms and one WebUserControl =
that contains a textbox and a button. I would like to display a string =
in the textbox when the WebForm1 is used, but another string when =
WebForm2 is used. How can I do this? Do I have to create 2 different =
classes and then reference them in the "@ Register" directive, like =
this?

In WebForm1:
<%@ Register TagPrefix=3D"uc1" TagName=3D"WebUserControl1" =
Src=3D"WebCtrlForForm1.ascx" %>=20

In WebForm2:
<%@ Register TagPrefix=3D"uc1" TagName=3D"WebUserControl1" =
Src=3D"WebCtrlForForm2.ascx" %>=20

But what about the default class that is created when I create the =
WebUserControl? Is it safe to delete it? Is the strategy I am indicating =
here correct at all?

Thanks
Mike
2/25/2004 10:59:30 PM

In a test project, I have created two WebForms and one WebUserControl =
that contains a textbox and a button. I would like to display a string =
in the textbox when the WebForm1 is used, but another string when =
WebForm2 is used. How can I do this? Do I have to create 2 different =
classes and then reference them in the "@ Register" directive, like =
this?

In WebForm1:
<%@ Register TagPrefix=3D"uc1" TagName=3D"WebUserControl1" =
Src=3D"WebCtrlForForm1.ascx" %>=20

In WebForm2:
<%@ Register TagPrefix=3D"uc1" TagName=3D"WebUserControl1" =
Src=3D"WebCtrlForForm2.ascx" %>=20

But what about the default class that is created when I create the =
WebUserControl? Is it safe to delete it? Is the strategy I am indicating =
here correct at all?

Thanks
AddThis Social Bookmark Button