Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Change Window- Button Clicked

Posted on 2008-11-13
10
Medium Priority
?
173 Views
Last Modified: 2012-05-05
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!
0
Comment
Question by:jjrr007
  • 5
  • 4
10 Comments
 
LVL 17

Expert Comment

by:Daniel Reynolds
ID: 22955413
in the code behind for the button you can do the following

Response.Redirect("mypage.aspx");
0
 
LVL 17

Expert Comment

by:Daniel Reynolds
ID: 22955427
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
 
LVL 1

Author Comment

by:jjrr007
ID: 22955557
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 17

Accepted Solution

by:
Daniel Reynolds earned 2000 total points
ID: 22955621
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
 
LVL 1

Author Comment

by:jjrr007
ID: 22955687
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
 
LVL 17

Expert Comment

by:Daniel Reynolds
ID: 22955841
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
 
LVL 8

Expert Comment

by:tiagosalgado
ID: 22956338
Where is your button placed? First you have posted a submit function and then you post a different function for same button.
0
 
LVL 1

Author Comment

by:jjrr007
ID: 22956962
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
 
LVL 17

Expert Comment

by:Daniel Reynolds
ID: 22961793
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
 
LVL 1

Author Comment

by:jjrr007
ID: 22962702
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question