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.
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,
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
Don't see what you're looking for? Try a search.
|