M
mark4asp
How can I stop a post back from firing when there is no need for it
to?
I have a GridView pager template (shown below):
There are 3 commands:
ddlPager_SelectedIndexChanged - move the page to the selected number
lnkPagerBack_Click - move back one page
lnkPager_Click - move forward one page
How can I stop lnkPagerBack_Click from posting back when the current
page number is 1 (a minimum) and stop lnkPager_Click from posting back
when the current page number is at a maximum?
I would prefer to raise a javascript alert but I don't see how I can.
<PagerTemplate>
<div id="PageRow">
<asp:label id="MessageLabel" CssClass="lblPagerMessage"
text="Select a page:"
Runat="server" />
<aspropDownList id="ddlPager" AutoPostBack="true"
CssClass="ddlPagerDDL"
OnSelectedIndexChanged="ddlPager_SelectedIndexChanged"
Runat="server" />
<span>
<asp:LinkButton ID="lnkPagerBack" ToolTip="Previous"
runat="server" OnClick="lnkPagerBack_Click"
CssClass="lblPagerArrow" Text=" < " />
<asp:LinkButton ID="lnkPager" ToolTip="Next"
runat="server" OnClick="lnkPager_Click"
CssClass="lblPagerArrow" Text=" > " />
</span>
<asp:label id="CurrentPageLabel"
CssClass="lblPagerCurrent"
Runat="server" />
</div>
</PagerTemplate>
The server code is:
protected void ddlPager_SelectedIndexChanged(object sender, EventArgs
e)
{
GridViewRow pagerRow = gvAwarded.BottomPagerRow;
DropDownList pageList;
if (pagerRow != null)
{
pageList =
(DropDownList)pagerRow.Cells[0].FindControl("ddlPager");
gvAwarded.PageIndex = pageList.SelectedIndex;
}
BindGridView();
}
protected void lnkPager_Click(object sender, EventArgs e)
{
gvAwarded.PageIndex++;
BindGridView();
}
protected void lnkPagerBack_Click(object sender, EventArgs e)
{
if (gvAwarded.PageIndex > 0)
gvAwarded.PageIndex--;
BindGridView();
}
to?
I have a GridView pager template (shown below):
There are 3 commands:
ddlPager_SelectedIndexChanged - move the page to the selected number
lnkPagerBack_Click - move back one page
lnkPager_Click - move forward one page
How can I stop lnkPagerBack_Click from posting back when the current
page number is 1 (a minimum) and stop lnkPager_Click from posting back
when the current page number is at a maximum?
I would prefer to raise a javascript alert but I don't see how I can.
<PagerTemplate>
<div id="PageRow">
<asp:label id="MessageLabel" CssClass="lblPagerMessage"
text="Select a page:"
Runat="server" />
<aspropDownList id="ddlPager" AutoPostBack="true"
CssClass="ddlPagerDDL"
OnSelectedIndexChanged="ddlPager_SelectedIndexChanged"
Runat="server" />
<span>
<asp:LinkButton ID="lnkPagerBack" ToolTip="Previous"
runat="server" OnClick="lnkPagerBack_Click"
CssClass="lblPagerArrow" Text=" < " />
<asp:LinkButton ID="lnkPager" ToolTip="Next"
runat="server" OnClick="lnkPager_Click"
CssClass="lblPagerArrow" Text=" > " />
</span>
<asp:label id="CurrentPageLabel"
CssClass="lblPagerCurrent"
Runat="server" />
</div>
</PagerTemplate>
The server code is:
protected void ddlPager_SelectedIndexChanged(object sender, EventArgs
e)
{
GridViewRow pagerRow = gvAwarded.BottomPagerRow;
DropDownList pageList;
if (pagerRow != null)
{
pageList =
(DropDownList)pagerRow.Cells[0].FindControl("ddlPager");
gvAwarded.PageIndex = pageList.SelectedIndex;
}
BindGridView();
}
protected void lnkPager_Click(object sender, EventArgs e)
{
gvAwarded.PageIndex++;
BindGridView();
}
protected void lnkPagerBack_Click(object sender, EventArgs e)
{
if (gvAwarded.PageIndex > 0)
gvAwarded.PageIndex--;
BindGridView();
}