Reputation: 1
I am using a DataList for custom paging implementation and the button click is working locally but after deploying it in my godaddy server the button click showing a __doPostBack is not defined error
The DataList code is in the Usercontrol
<asp:DataList CellPadding="1" RepeatDirection="Horizontal" runat="server" ID="dlPager" onitemcommand="dlPager_ItemCommand">
<ItemTemplate>
<asp:LinkButton Enabled='<%#Eval("Enabled") %>'
runat="server" ID="lnkPageNo"
Text='<%#Eval("Text") %>'
CommandArgument='<%#Eval("Value") %>'
CommandName="PageNo"
BorderStyle="Solid"
BorderWidth="2px"
Font-Bold="True"
Font-Size="Medium"
ForeColor="White"
BackColor="#0066FF"
BorderColor="#66FF33"
Height="20px"
CausesValidation="False">
</asp:LinkButton>
</ItemTemplate></asp:DataList>
And the View Source of the page shows,
<table id="ctl00_cphBody_ctl00_dlPager" cellspacing="0" cellpadding="1" CausesValidation="False" border="0" style="border-collapse:collapse;">
<tr>
<td>
<input type="button" name="ctl00$cphBody$ctl00$dlPager$ctl00$lnkPageNo" value="1" id="ctl00_cphBody_ctl00_dlPager_ctl00_lnkPageNo" disabled="disabled" style="color:White;background-color:#0066FF;border-color:#66FF33;border-width:2px;border-style:Solid;font-size:Medium;font-weight:bold;height:20px;" />
</td><td>
<input type="button" name="ctl00$cphBody$ctl00$dlPager$ctl01$lnkPageNo" value="2" onclick="javascript:__doPostBack('ctl00$cphBody$ctl00$dlPager$ctl01$lnkPageNo','')" id="ctl00_cphBody_ctl00_dlPager_ctl01_lnkPageNo" style="color:White;background-color:#0066FF;border-color:#66FF33;border-width:2px;border-style:Solid;font-size:Medium;font-weight:bold;height:20px;" />
</td><td>
<input type="button" name="ctl00$cphBody$ctl00$dlPager$ctl02$lnkPageNo" value="3" onclick="javascript:__doPostBack('ctl00$cphBody$ctl00$dlPager$ctl02$lnkPageNo','')" id="ctl00_cphBody_ctl00_dlPager_ctl02_lnkPageNo" style="color:White;background-color:#0066FF;border-color:#66FF33;border-width:2px;border-style:Solid;font-size:Medium;font-weight:bold;height:20px;" />
</td>
</tr>
User control code behind
protected void dlPager_ItemCommand(object source, DataListCommandEventArgs e)
{
if (e.CommandName == "PageNo")
{
GetData(Convert.ToInt32(e.CommandArgument));
}
}
And the page load is
if (!Page.IsPostBack)
{
GetData(1);
}
I tried the solution mentioned in other similar threads but none worked.
I can see the doPostback scipt is already present in the viewsource of the page. I am using VS 2010
Upvotes: 0
Views: 1659
Reputation: 7943
You need to add Page.ClientScript.GetPostBackEventReference(this, string.Empty);
to the link button's OnClick
event. So you have to do it in dlPager_ItemDataBound
, where you can find the LinkButton
from e.Item.FindControl
. Your code might look like this:
protected void dlPager_ItemDataBound(object sender, DataListItemEventArgs e)
{
var lb = e.Item.FindControl("lnkPageNo") as LinkButton;
if (lb != null)
{
lb.Attributes["onclick"] = Page.ClientScript.GetPostBackEventReference(this, string.Empty);
}
}
Upvotes: 1