2
\$\begingroup\$

I've got a 'menu' within a Master page which include a number of image buttons with click events.

Within each click event, I want to redirect the user to a specific page. However, if the user is already on the correct page, I don't want to refresh the page.

In the example below, if the user is already on browse.aspx, I don't want to refresh it, however, otherwise I want to redirect the user to browse.aspx.

Is the following code the best way to go about this?

protected void ibtnBrowse_Click(object sender, ImageClickEventArgs e)
{
    if (!Request.Url.Segments[1].ToString().Equals("browse.aspx"))
    {
        Response.Redirect("~/browse.aspx");
    }
}
\$\endgroup\$
3
\$\begingroup\$

I don't think you should do this. When I click a button, it should do something, when it doesn't do anything, it's confusing.

So, when the user clicks on something that is supposed to take him to the page they're already on, it should refresh the page.

For example, Stack Exchange does this: try clicking on the question title here, or on the site name on the main page.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.