Reputation: 51
In the following code I am trying to prevent autopostback, to not to load the page again. But this is not working. Is there any other way I can disable AutoPostBack on button click ? I know there is no autopostback property for LinkButton but I want to know if I can do it.
<asp:LinkButton runat="server" ID="myBtn" onclick="myBtn_Click" CssClass="btn" AutoPostBack="false"></asp:LinkButton>
Upvotes: 0
Views: 4078
Reputation: 5818
There is no default property to set AutoPostBack
for LinkButton
. But you can add HTML attributes to do that.
<asp:LinkButton runat="server" ID="myBtn" onclick="myBtn_Click" CssClass="btn" AutoPostBack="false"></asp:LinkButton>
Add this in the Page_Load
event which will stop the event from Client Side.
protected void Page_Load(object sender, EventArgs e)
{
myBtn.Attributes.Add("onClick", "return false;");
}
or more simply with OnClientClick
<asp:LinkButton runat="server" ID="myBtn" onclick="myBtn_Click" CssClass="btn" OnClientClick="function(){ return false; }"></asp:LinkButton>
Upvotes: 1