Aravinda
Aravinda

Reputation: 19

Adding button click event to reponse.redirect

I want to know if I could add a button click event after response.redirect().

protected void lnkEdit_Click(object sender, EventArgs e)
{
     LinkButton lnkEdit = (LinkButton)sender;
     string sno = lnkEdit.CommandArgument;
     Response.Redirect(string.Format("HomePage.aspx?eid={0}", sno));
}

this is my code. I want to redirect to a page which comes after clicking a button present in HomePage.aspx page without changing the url.

Upvotes: 1

Views: 636

Answers (2)

SanyTiger
SanyTiger

Reputation: 666

Try this

public void Button1_Click(object sender, System.EventArgs e) 
{ 
        string sno = lnkEdit.CommandArgument;
        if(sender)
        Response.Redirect("HomePage.aspx?eid=" + sno);
}

Upvotes: 0

mybirthname
mybirthname

Reputation: 18127

Your question is not exactly clear.

If you want to redirect to other page without changing the url you can use:

Server.Transfer(string.Format("HomePage.aspx?eid={0}", sno));

Here is server transfer documentation.

You can't add button click event after system Redirect. The execution of current page will be terminated after Redirect. If you want to execute something after redirecting, you can redirect to page with specific query param and on loading of the redirected page, execute wanted logic if the param is true.

Upvotes: 2

Related Questions