LinkButton PostBackUrl

  • Thread starter Thread starter Jon
  • Start date Start date
J

Jon

Hello all,

I have a LinkButton with the PostBackUrl set, I also have an OnClick
event set.

For some reason, the OnClick event is only hit the second time I click
the LinkButton. If I remove the PostBackUrl attribute it hits it every
time. Why is that?

Thanks,

Jon
 
Hi Jon,

I believe postbackURL lets the button post to a different page. I am
assuming you want to redirect the user in some way? Instead, set the button's
commandargument property to the URL you want, and then at the end of the
OnClick event, redirect the user to the value of the CommandArgument Property.

You can refer to the code below for this:

protected void LinkButton1_clk(object sender, EventArgs e)
{
if (someVariable == 2)
{
Response.Redirect(LinkButton1.CommandArgument.ToString());
}
}

Hope this helps.

Regards,
Manish
 
Back
Top