ASP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingASP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old June 9th, 2003, 02:40 PM
thai21 thai21 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 3 thai21 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #2  
Old June 11th, 2003, 04:13 PM
James Yang James Yang is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Atlanta, Georgia
Posts: 284 James Yang User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 45 sec
Reputation Power: 7
Send a message via ICQ to James Yang
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/

Reply With Quote
  #3  
Old June 11th, 2003, 04:14 PM
James Yang James Yang is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Atlanta, Georgia
Posts: 284 James Yang User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 45 sec
Reputation Power: 7
Send a message via ICQ to James Yang
oh and if u don't have access to uc object then u can do this

Textbox a = (Textbox)Page.Controls[INDEXGOESHEREDEPENDINGONWHENUINSERTUC].Controls[indexagain]

Reply With Quote
  #4  
Old June 11th, 2003, 05:53 PM
thai21 thai21 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 3 thai21 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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!

Reply With Quote
  #5  
Old June 12th, 2003, 03:50 PM
James Yang James Yang is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Atlanta, Georgia
Posts: 284 James Yang User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 45 sec
Reputation Power: 7
Send a message via ICQ to James Yang
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

Reply With Quote
  #6  
Old June 12th, 2003, 04:41 PM
thai21 thai21 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 3 thai21 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingASP Development > asp.net usercontrols


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT