Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loading Another Page Programmatically 2

Status
Not open for further replies.

WoundEdGoat

Programmer
May 10, 2002
39
0
0
CA
Could someone please tell me how to load another page programmatically? What I'm trying to accomplish is for the user to login information and be taken to the profile page (or something similar to such a thing) via a button click. I unfortunately have no idea how to send the program to another page without a hyperlink.

Your help is much appriciated. Thanks.
 
Two common ways:

Code:
[green]'tells the client to request a different page[/green]
Response.Redirect("AnotherPage.aspx")

[green]'starts executing another page (but the client doesn't know it.)[/green]
Server.Transfer("AnotherPage.aspx")

I prefer Response.Redirect().

Greetings,
Dragonwell


 
One other thing, how would I pass parameters back and forth between pages using this method?

Thanks.
 
you could use query strings

Response.Redirect("AnotherPage.aspx?ID=" & loginID)
 
Oops... Just realized that I don't know how to catch the query strings on the targat page. Help?
 
Could use,
string qsValue = Convert.ToString(Request.QueryString["qsName"]);
 
Thanks dragonwell. I have a cancel button that I'd like to take the user one page back. How do I do that?
 
I was hoping for something I could put in the code behind file:

Code:
Private Sub cmdCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCancel.Click

End Sub
 
you can add the attribute to the button in the code behind...

Code:
btn.attributes.add("onclick","javascript: history.go(-1); return false;")

dlc
 
Guys,
I've got a Cancel and a Save button (with a required validator on the Save). I have a textbox also. When the user clicks the Save button, the validation is done to ensure the textbox is populated, and then it executes the Save code:
Code:
Response.Redirect("nextpage.aspx")

When the user clicks the Cancel button, I'd like the application to:
1. Skip the validation on the textbox
2. Go back one page

When I use the code suggested:

Code:
    Private Sub cmdCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCancel.Click
        cmdCancel.Attributes.Add("onClick", "javascript: history.go(-1); return false;")
    End Sub

it doesn't work! When I click on cancel, the validation is done (i.e. checks if the textbox is populated, and will not continue until it is). After I populate the textbox and hit cancel, it just reloads the page!

Why is that?

Thanks
 
You don't want the Cancel button to cause validation? just put CausesValidation="False" in the button tag's attributes.

Code:
<asp:Button runat="server" CausesValidation="False" id="cmdCancel" Text="Cancel" />

Greetings,
Dragonwell
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top