Click here to Skip to main content
15,908,455 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have using linkbutton for making whole div clickable inside updatepanel..but when i click div whole it have postback.. so please help how to avoid postback?

What I have tried:

<asp:UpdatePanel ID="UpdatePanel2" UpdateMode="Conditional" ChildrenAsTriggers="false" runat="server">
<triggers> <asp:AsyncPostBackTrigger ControlID="rptEmployer" />
<contenttemplate>

<asp:TextBox ID="txtsearch" CssClass="srch" AutoPostBack="true" runat="server" placeholder="Search Employer" OnTextChanged="txtsearch_TextChanged">
<asp:Repeater ID="rptEmployer" OnItemCommand="rptEmployer_ItemCommand" runat="server">
<itemtemplate>
<asp:LinkButton ID="lb_emp_list" Style="text-decoration: none;" CommandName="Edit" runat="server">


<%# Eval("RowNumber") %>


Tax Id : <%# Eval("EmployerTaxId") %>

<%# Eval("name") %>



<asp:HiddenField ID="hdn_EmpTax_Id" Value='<%# Eval("EmployerTaxId") %>' runat="server" />
<asp:HiddenField ID="hdn_CompanyTax_Id" Value='<%# Eval("CompanyTaxID") %>' runat="server" />






Posted
Updated 21-Jul-16 9:48am

Delete Command Name as "CommandName="Edit"" inside <asp:linkbutton xmlns:asp="#unknown">,replace it with "OnClick="clientCallPostBack()", put ClientIDMode as "Static" on updatepanel,Create a javascript function in same page's client side as below,

<asp:updatepanel id="UpdatePanel2" runat="server" clientidmode="Static">

ASP.NET
<asp:LinkButton ID="lb_emp_list" Style="text-decoration: none;" OnClick="clientCallPostBack(); runat="server">


function clientCallPostBack(){

__doPostBack('<% UpdatePanel2.ClientID %>');
return;
}


Then,doing somethings at code behind as below at Prerender Stage,

if (ScriptManager.GetCurrent(Page).IsInAsyncPostBack)
{
var Target = Request.Params.Get("__EVENTTARGET");
if (!String.IsNullOrEmpty(Target))
{
switch (Target)
{
case "UpdatePanel2":
//doing somethings here............
break;
}
}
}
Remember "__doPostBack" agains to updatepanel will manage to invoke Asyncpostback without Postback.,Of cause you can do it in jquery to document ready in client side for easier to Link Button click.
 
Share this answer
 
v3
Put ClientIdMode="Auto"

ASP.NET
<asp:LinkButton ClientIdMode="Auto" ID="lb_emp_list" Style="text-decoration: none;" OnClick="clientCallPostBack(); runat="server">
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900