Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Accessing form variables in user control
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Accessing form variables in user control

 Post Reply Post Reply
Author
sabrin514 View Drop Down
Newbie
Newbie


Joined: 19 December 2003
Status: Offline
Points: 26
Post Options Post Options   Thanks (0) Thanks(0)   Quote sabrin514 Quote  Post ReplyReply Direct Link To This Post Topic: Accessing form variables in user control
    Posted: 29 November 2005 at 11:44am
Good morning,
 
I have a form in an aspx page which contains 2 user controls. These two user controls each contain items normally found in a form (such as text boxes). The submit button (and event) is located in the .aspx page.
 
My problem is that I cannot seem to access the values contained within the text boxes located in the user controls when I go to submit the form.
 
Any help would be greatly appreciated. Been bashing my head on the desk all morning :(
 
Thanks!
Back to Top
michael View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 April 2002
Location: United States
Status: Offline
Points: 4670
Post Options Post Options   Thanks (0) Thanks(0)   Quote michael Quote  Post ReplyReply Direct Link To This Post Posted: 29 November 2005 at 3:42pm
Did you make the textbox private?
 
If in the User Control you do
Private x as new Textbox
it will not work
Do something like
Friend x as new Textbox
or
Public x as new Textbox
 
Then you should be able to read
 
Dim s as string = myControl.x.Text
Back to Top
sabrin514 View Drop Down
Newbie
Newbie


Joined: 19 December 2003
Status: Offline
Points: 26
Post Options Post Options   Thanks (0) Thanks(0)   Quote sabrin514 Quote  Post ReplyReply Direct Link To This Post Posted: 29 November 2005 at 3:53pm
Thank you very much for your response.
 
In my user Control  (fm_ex_provider_info.ascx) I have a textbox declared as:
 
Public txtBusinessName As New System.Web.UI.WebControls.TextBox
 
And related code:
 
Public ReadOnly Property ProvBusinessName() As String
    Get
        Return Me.txtBusinessName.Text
    End Get
End Property
 
-----------------------------------------------------------------
 
Then in my host form (ex_provider_input.aspx) I have:
 
Dim ProviderForm As fm_ex_provider_info1 = DirectCast(Me.ProviderForm, fm_ex_provider_info1)     [Declared in top variable section]
 
Dim BusinessName As String = ProviderForm.ProvBusinessName    [This piece of code is in the submit button event)
 
-----------------------------------------------------------------
 
 
The page loads just fine, but I get an error about the object not being set to an instance of the object when I hit the sub,it button. The error appears to be caused by this line of code" "Dim BusinessName As String = ProviderForm.ProvBusinessName ".
 
Apparently I am missing something. If anyone has any ideas, I would be very grateful. Thank you.
 
 
 
 


Edited by sabrin514 - 29 November 2005 at 3:53pm
Back to Top
sabrin514 View Drop Down
Newbie
Newbie


Joined: 19 December 2003
Status: Offline
Points: 26
Post Options Post Options   Thanks (0) Thanks(0)   Quote sabrin514 Quote  Post ReplyReply Direct Link To This Post Posted: 30 November 2005 at 10:06am
Problem was fixed by the following:
 
Dim ProviderForm As fm_ex_provider_info1  in variable declaration section
 
 
Then in page load:
 
ProviderForm = DirectCast(page.findcontrols("fm_ex_provider_info1", fm_ex_provider_info1))
 
 
Finally in submit button event:
 
Dim BusinessName As String = ProviderForm.ProvBusinessName  
 
Response.Write(strBusinessName)  'For testing purposes
 
 
Thanks to everyone that was looking into this.
 
 
 
 
 
 


Edited by sabrin514 - 30 November 2005 at 10:07am
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.