|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Passing values bewteen user controls is separate web formsHi! I have what I hope is a simple problem. I have 2 web forms. The
first form is a welcome page with a textbox and button (in a user control). What's supposed to happen is that a user will enter data in the textbox and click the button. The event handler for the button then has to send that value to a the second web form containing a user control that can accept that value as a parameter in a db query and display the user control with the results of the query. I can set the value of the query in the user control and display the page on its own, but how do I get the textbox value from another form? I'll happily supply code if my description isn't clear. Thanks, campwes Hi,
I guess you are a newby, because this is normally the first question every newby asks, and your next question will be on how to do a databse query, so here we go.... if you have a textbox called NameTextBox, then on the button click event you can use one of many options to pass the value to the next page, but I will use the session state to do this, so here is how to: on the click event do the following: Session("userName") = NameTextBox.Text, this will put the value of the textbox into the session state object, more specifically it will link it to the "userName" variable in the session state, just think of the session state as one big hashtable. Now on any page in the project you can refer to this value by simply doing this: Dim _UserName as String = cstr(Session("userName")), this will retrieve the whatever is held in the userName variable in the session state object, cast it to string and assign it to your variable. Now for the SQL part press F1 and look under SqlCommand and you will see good examples. Rykie Rykie,
Thank you for the suggestion. One thing I am not clear on is how the value from the textbox1.Text field gets to the database query. When a user enters a number in the text field and clicks the Send button from the 1st user control, the 2nd user control must receive this number as a parameter in a query ("...where question_number =" & qNum & "...) and display its page data (2nd user control, UI, etc). Thanks again for the help. Regards, campwes Campwes,
As I said before, look under SQLCommand on MSDN. There are a number of ways you can do this, but the one I will do will be in your first dropdownlist postback event I will do a databse query and set the second ddl datasource there. Ryk Rykie,
I don't need to know how to do a database query. That's wasn't my problem. If there's anyone else reading this who wants the answer, here it is... http://msdn2.microsoft.com/en-us/library/6c3yckfw.aspx
how do I call a SQL Server stored procedure?
Application.Run Problem blank form when debugging Write to an existing ASCII file Detecting process start Get Minimum and Maximum date Simple data grid question adding BG to forms. Convert local time(eg EST) on local machine to GMT Get POP server from email address |
|||||||||||||||||||||||