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!
LVL 1
jjrr007Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Daniel ReynoldsSoftware Applications Developer / IntegratorCommented:
in the code behind for the button you can do the following

Response.Redirect("mypage.aspx");
0
Daniel ReynoldsSoftware Applications Developer / IntegratorCommented:
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.aspx");
0
jjrr007Author Commented:
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.
        protected void Submit1_Click(object sender, GridViewSelectEventArgs e);
    {
        Server.Transfer("PageResults.aspx");
 
    }

Open in new window

0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

Daniel ReynoldsSoftware Applications Developer / IntegratorCommented:
I would use the response.Redirect.

Response.Redirect("PageResults.aspx");

Be sure to tag on any parameters to the url.
and if your destination page is not in the same directory as your calling page, you will need to add the path into the redirect.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jjrr007Author Commented:
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");
 
    }

Open in new window

0
Daniel ReynoldsSoftware Applications Developer / IntegratorCommented:
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.
0
tiagosalgadoCommented:
Where is your button placed? First you have posted a submit function and then you post a different function for same button.
0
jjrr007Author Commented:
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!
0
Daniel ReynoldsSoftware Applications Developer / IntegratorCommented:
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.

0
jjrr007Author Commented:
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.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.