User controls

M

Mike

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="uc1" TagName="WebUserControl1" Src="WebCtrlForForm1.ascx" %>

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

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
 
R

Raterus

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 = myText

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

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

Hope this helps,
--Michael

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="uc1" TagName="WebUserControl1" Src="WebCtrlForForm1.ascx" %>

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

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top