all groups > asp.net building controls > september 2004 >
You're in the

asp.net building controls

group:

Getting variables from other controls & forms


Getting variables from other controls & forms Rock
9/27/2004 12:04:46 PM
asp.net building controls: How do I get a value of a textbox control from a form?

On form1, I have a textbox with the value "CountyID" with a submit button;
when the user clicks on Submit, it goes to Form2.

How do I get the value of "countyID" (or whatever the user enters into the
textbox) to display on form2?

Something like request.Params("???"). request.Form????

Request Two:
If I put the forms into user controls, what would I do to get the
information the user has selected? This is what I've tried:
default.aspx has 2 controls: Ctrl1 and Ctrl2.
Ctrl1 has a drop down list, say ddlCounty
ddlCounty.SelectedItemChanged raises a public event
SelectedItemChanged, with a ReadOnly property SelectedItem, which returns
ddlCounty.SelectedItem
Public ReadOnly Property SelectedItem() As
ListItem

Get

Return ddlCounty.SelectedItem

End Get

End Property


Ctrl2 on postback tries to read the selectedItem property
from Ctrl1:
Dim x As New ctrl1
Response.Write(x.SelectedItem)


When run, I get this error:

Exception details: Object Reference Not Set to an instance of an object
Source Error:

Line 66: Public ReadOnly Property SelectedItem() As ListItem
Line 67: Get
Line 68: Return ddlCounty.SelectedItem
Line 69: End Get
Line 70: End Property



Thanks.


Re: Getting variables from other controls & forms dbloodworth NO[at]SPAM infinitechs.com
10/14/2004 11:39:25 AM
Rock,

Here's an attempt to answer your questions. Hope I'm understanding
the problem correctly.

First: In ASP.NET use Request.Params("[name of control]"). Classic
ASP uses Request.Form("[name of control]"). For what it's worth,
Request.Querystring() is the same in both.

For the second request: If I'm not mistaken you need to add .Value to
your SelectedItem property. Again this is fuzzy, but I think that
SelectedItem is an object and SelectedItem.Value is just that (the
value of the object).

HTH,

Re: Getting variables from other controls & forms Mohanad Haddadin
10/18/2004 12:15:10 AM
hi
Request.Params is a good idea. You can also use Page.FindControl("control
ID"), and it must be executed in run time so you can use the following code
in the CreateChildControls or render method

if (!DesignMode)
{
TextBox TextBox1 =(TxtBox) Page.FindControl("ControlID");
string text = TextBox1.Text;
}

I hope this can be helpful
thank you

AddThis Social Bookmark Button