Monday, March 26, 2012

Ok, an EASY way to extract Request GET/POST vairbales?

Alright, I'm running the the Wrox Beggining ASP.Net and the ASP.Net Bible, and it looks like extracting Request.Form and Request.QueryString just got insanely and ridiculously hard.

I'm trying to pass just a few parameters to a page, and I can't even get them in there... Help!

Is there a tutorial on here that shows an EASY method for pulling the data that's passed to a dotNet page?

Thanks for the help.Don't understand what's so difficult. For example:

QueryString (http://www.domain.com/default.aspx?id=1)

 Request.QueryString [ "id" ]; // C#
Request.QueryString ( "id" ) ' VB
Form
 Request.Form [ "id" ]; // C#
Request.Form ( "id" ) ' VB
Params
 Request.Params [ "id" ]; // C#
Request.Params ( "id" ) ' VB
If you need to know how to access them dynamically (i.e. not knowing the keys before hand) see the examples provided forHttpRequest.QueryString andHttpRequest.Form

HTH
if this is your link
out.aspx?id=1&name=Jake

In out.aspx


Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
Dim intID As Integer
Dim strName As String
intID = Request.QueryString("id")
strName = Request.QueryString("name")
response.write("Hello " & strName & " you clicked link # " & intID)
End If
End Sub

As for form variables, you don't post them to a new page like you're thinking. You post the form to itself and in the code section you just reference the control name.

If you had a textbox called fName then fName.text is equal to request.form("fname").

0 comments:

Post a Comment