|
-
Jan 17th, 2007, 10:18 AM
#1
Thread Starter
Member
Need help with WebUserControl
Hello.
I'm having some trouble with webusercontrols. I've created one with a checkbox and a textbox. Now, I want to create three of these when my page loads. I'm using this code for that (I'm also using a placeholder):
Code:
WebUserAlternative uc1;
for (int i = 0; i < 3; i++)
{
uc1 = (WebUserAlternative)Page.LoadControl("~/WebUserAlternative.ascx");
uc1.ID = "nr" + i;
PlaceHolder1.Controls.Add(uc1);
}
Now to my problem.
How do I check the text that has been written in each of those textboxes (the textbox inside the webusercontrol) and if the checkboxes are checked?
I know how to do this when I "pre-create" (not on the fly) one webusercontrol, but I can't figure out how to get the text from all the textboxes etc that are created on page_load.
Damn, that was messy Anyway.. I hope you guys understand my problem.
-
Jan 17th, 2007, 11:45 AM
#2
Re: Need help with WebUserControl
Have you created properties in your usercontrol to access these values already?
Properties in usercontrol...
Code:
public string EmailAddress
{
get { return this.txtEmail.Text.Trim(); }
set { this.txtEmail.Text = value; }
}
To access dynamic controls at runtime
Code:
foreach (Control c in this.placeholder.Controls)
{
if (c.GetType().ToString() == "ASP.mycontrol_ascx")
{
myString = ((mycontrol)c).EmailAddress;
}
}
Hope that helps.
-
Jan 17th, 2007, 05:36 PM
#3
Thread Starter
Member
Re: Need help with WebUserControl
-
Jan 18th, 2007, 01:23 AM
#4
Thread Starter
Member
Re: Need help with WebUserControl
Btw... I tried to put this code in a dropDownList_SelectedIndexChanged method. But that doesn't work. It only seems to work when I put it in page_load.
Does anyone know how to fix that?
It's not that important... I'm just curious as to why it doesn't work.
-
Jan 18th, 2007, 03:43 AM
#5
Re: Need help with WebUserControl
Because selecting an index of DropDownList doesn't fire the event. Place a Breakpoint inside dropDownList_SelectedIndexChanged method, run the application and change its index.
Change the AutoPostBack property of dropDownList to True, it will give you the desired result.
-
Jan 18th, 2007, 08:09 AM
#6
Thread Starter
Member
Re: Need help with WebUserControl
Thanks for answering, but I've already tried that. Doesn't work (at least for me it doesn't). Oh well.. I'll play around with it some more and see what I can come up with.
-
Jan 18th, 2007, 08:41 AM
#7
Re: Need help with WebUserControl
 Originally Posted by korven
Btw... I tried to put this code in a dropDownList_SelectedIndexChanged method. But that doesn't work. It only seems to work when I put it in page_load.
Does anyone know how to fix that?
It's not that important... I'm just curious as to why it doesn't work.
What do you mean exactly when you say it doesn't work?
Are you re-creating your controls on each page load?
-
Jan 24th, 2007, 09:28 AM
#8
Re: Need help with WebUserControl
Does the SelectedIndexChanged event actually get hit?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|