NaveedAnjum
NaveedAnjum

Reputation: 3

redirect to new page when i click on Cancel button in C# (webpart)

// Cancel button
            tc = new TableCell();
            btnCancel = new Button();
            btnCancel.Text = "Cancel";
            btnCancel.Click += new EventHandler (btnCanel_Click ) ;
            tc.Controls.Add(btnCancel);
            tr.Controls.Add(tc);

            t.Controls.Add(tr);


            // Empty table cell
            tr = new TableRow();
            tc = new TableCell();
            tr.Controls.Add(tc);

            this.Controls.Add(t);
        }

        protected void btnCanel_Click(object sender, EventArgs e)
        {

        }

What i am tring to do is . when i click on Cancel button it redirect me to "Example.aspx". i am create a webpart using C#

Upvotes: 0

Views: 1363

Answers (3)

kakridge
kakridge

Reputation: 2293

To do exactly what you want, on the server, would be Response.Redirect. There is no need to postback though. There are a few client side solutions. Use a LinkButton, w/ onclick html attribute set to false. My recommendation is something like this though:

<INPUT TYPE="BUTTON" VALUE="Cancel" ONCLICK="window.location.href='http://www.yourdomain.com/example.aspx'"> 

Upvotes: 0

Yet Another Geek
Yet Another Geek

Reputation: 4289

Call the HttpResponse.Redirect Method.

Example:

Response.Redirect("Example.aspx");

Upvotes: 0

The Evil Greebo
The Evil Greebo

Reputation: 7138

protected void btnCanel_Click(object sender, EventArgs e)
{
    Response.Redirect("example.aspx");
}

Upvotes: 1

Related Questions