|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
asp.net usercontrols
Hello,
I am having problems trying to use a UserControl in asp.net. I created the control, then in my web form I added the following code to add the control: -- code -- Control uc; uc = LoadControl("MyControl.ascx"); this.phUserControl.Controls.Add(uc); // added the control to the placeholder -- end code -- Ok, now the control is added, the control has an input text box named TextBox1. My webform has a button (btnSave), how can I have my btnSave's onclick event read the TextBox1.Text from the UserControl? Before you ask why I don't want to put the Save button on the user control, its because I will have different controls on the form and the save button will read all of them. Please help if you can. Thanks. Thai |
|
#2
|
|||
|
|||
|
You can access the textbox in uc by accessing control property of us
so uc.Controls[INDEXNUMBER] if u wanna use the texbox properties then u can cast it (lets say the textbox is ur 5th control in the usercontrol Textbox a = ((Textbox)uc.Control[4]);
__________________
Regards, James Yang .NET Developer / Network Engineer MCSE, MCDBA, MCSA, CCNA http://www.yellowpin.com/ http://www.opentechsupport.com/ |
|
#3
|
|||
|
|||
|
oh and if u don't have access to uc object then u can do this
Textbox a = (Textbox)Page.Controls[INDEXGOESHEREDEPENDINGONWHENUINSERTUC].Controls[indexagain] |
|
#4
|
|||
|
|||
|
Thanks for the reply!
When I add the control to the webform, I can't even reference the uc. When I type <controname>. nothing comes up. The intellisense doesn't detect it. On a side note, if I add the control via code.. how do I find the index of the user control on the webform? Thanks! |
|
#5
|
|||
|
|||
|
well there are several wasy to do it..what i do is this
just loop through each item in the collection and print it's name using reflexion..and see which ones urs.... but i think if u can't reference it then there is something wrong with ur code .... post ur code and ill have a look at it |
|
#6
|
|||
|
|||
|
Hi James,
Can you send me an email to URL and I'll reply with my project attached? Its a small test project with 1 web form and 1 user control. Thanks, I really appreciate your help. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > ASP Development > asp.net usercontrols |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|