jjrr007
asked on
Change Window- Button Clicked
I wanted to please ask how can I navigate to a new page when a button is clicked. In other words, when a button is clicked I want to navigate to new page (without opening a new window). I prefer the simplest way to do this. I am using ASP.NET and C# with Visual Studio 2005. I prefer to just use asp.net. Thanks!
Another method, is to transfer the response object. (Review the differences between Server.Transfer and Response.Redirect)
In the code behind for the button you would put the following.
Server.Transfer("mypage.as px");
In the code behind for the button you would put the following.
Server.Transfer("mypage.as
ASKER
Thanks for your time. I am getting a syntax error with the code listed in the snippet. How should i change it? Also what is the difference between the two ways you had it.
What I want to do is have a search box on the website. When the user types in something and presses the button, I want them to be directed to a page where they can see the search results. Based on that, which way would you recommend.
What I want to do is have a search box on the website. When the user types in something and presses the button, I want them to be directed to a page where they can see the search results. Based on that, which way would you recommend.
protected void Submit1_Click(object sender, GridViewSelectEventArgs e);
{
Server.Transfer("PageResults.aspx");
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I am not getting an error message, but the page is not changing. Below is the updated code. Maybe I am not calling the function correctly. what do you suggest?
protected void Submit1_Click(object sender, EventArgs e)
{
Response.Redirect("NewPage.aspx");
}
set a break point on the redirect line and make sure it is getting there.
Also, make sure that the Click event of the button is pointing at your submit1_click() method.
Also, make sure that the Click event of the button is pointing at your submit1_click() method.
Where is your button placed? First you have posted a submit function and then you post a different function for same button.
ASKER
Thanks for your responses. The button is placed near the top of the ASP.net page.
When I double clicked on the button, I am not directed to the C# code for the button. I can't tell for certain if the button is associated with the code properly. I had to make it up on my own. I think the last C# code seems better, but I don't know if it's right. The button's ID is Submit1. So based on my most recent code, do you think it is accurate?
I can try the breakpoint when I get in the office in the morning. I can let you know what happens. Thanks again!
When I double clicked on the button, I am not directed to the C# code for the button. I can't tell for certain if the button is associated with the code properly. I had to make it up on my own. I think the last C# code seems better, but I don't know if it's right. The button's ID is Submit1. So based on my most recent code, do you think it is accurate?
I can try the breakpoint when I get in the office in the morning. I can let you know what happens. Thanks again!
When in design mode, select the button. Press "F4" to display the properties for the button.
Select the little lightning bolt to show the event side of the properties.
Select the correct event for the click event.
and voila, you should hopefully be set.
Select the little lightning bolt to show the event side of the properties.
Select the correct event for the click event.
and voila, you should hopefully be set.
ASKER
I didn't see the lightning bolt when I first tried. I was using a different type of button. I have changed it to a regular button and it worked. Thanks for your time and patience with me.
Response.Redirect("mypage.