0

Hello

I have this line of VB.NET that redirects the user to a 'Thank you' page (thankyou.aspx) after submitting a contact form.

  Dim target = String.Format("~/thankyou.aspx?yourname={0}", Name)

        'Redirect user to thank you page

        Response.Redirect(target, True)

The contact form itself has this:

   <p><span>Name</span><input class="contact" type="text" name="your_name" /></p>

while in my aspx.vb code, I have:

    Dim Name As String = "yourname"
    Dim yourname As String = Request.Form("your_name")

Is this, therefore, correct?

Dim target = String.Format("~/thankyou.aspx?yourname={0}", Name)

I am not sure if it should be

("~/thankyou.aspx?yourname={0}", Name)

or

("~/thankyou.aspx?your_name={0}", Name)

And why this 'Name' at the end? Isn't that just a label?

Many thanks!

4
Contributors
15
Replies
29
Views
2 Years
Discussion Span
Last Post by Blueie
0

I think you will need QueryString not Form

Dim yourname As String = Request.QueryString("your_name")

You can then either make the input a proper asp textbox and set it's value in code behind, or you can just inject it into the page into the value attribute.

Hoep that makes sense.

0

Eg <p><span>Name</span><input class="contact" type="text" name="your_name" value="<%=yourname%>" /></p>

0

And why this 'Name' at the end? Isn't that just a label?

That is part of the String.Format method. The {0} is the placeholder and the variable Name contains the value so that the full string becomes "~/thankyou.aspx?yourname=whatever_the_name_variable_holds"

0

I just re read my answers and realised I didn't read your question properly and got mixed up with your contact page and the final page so just ignore all the stuff I said!

0

Hahahaha

I saw that your name was 'beer' in your profile!

I would need to specify the name of the thank you page, wouldn't I?

0

Hello djjeavons

Thank you for your reply.

So Name as I have it would be right?

0

Hi

Looking at your code you have a form element called your_name which you are then assigning to a variable called yourname, so assuming that this is what holds the name then you should be using the yourname variable.

0

If you use a textbox control instead of an html input element, you dont have to use Request.Form. You can access the control directly...

Instead of

<input class="contact" type="text" name="your_name" />

You can use...

<asp:TextBox ID="txtYourName" runat="server" CssClass="contact"></asp:TextBox>

Then, you can access the value, by...

txtYourName.Text
0

Thanks.

Whereas you have TextBox ID="txtYourName", wouldn't I need to have that as TextBox ID="your_name" to correspond to the SMTP and send mail references I already
have?

And so I would have something like this in the page redirect:

Dim target = String.Format("~/thankyou.aspx?yourname={0}", your_name.Text)

Response.Redirect(String.Format("~/thankyou.aspx?yourname={0}", your_name.Text), True)

Response.Redirect(target, True)

where 'yourname' is the variable as djjeavons says, and 'your_name.Text' would be the ID of the ASP Textbox field as I have indicated above?

Is that what you mean?

Thanks again.

0

Yes the ID I suggested could actually be anything you wish as long as there aren't any hyphens.

You could use the HTML elements also but since you are developing in asp.net, there are advantages in using asp.net controls.

0

I will start a 'test' site tomorrow using Visual Studio Textboxes and Labels, it's just that I had already put in a lot of hours doing it my way, but I suppose you're right!

0

There isnt a right or wrong way to do it, it just wanted to let you know that the option exists. You should use the appropriate tool for each scenario. I dont always use asp.net controls for every project/every page.

0

Yes, I agreee, Jorge.

No doubt I will be back here soon with ASP redirection queries and Textboxes!

Thanks again.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.