How can I stop a post back from firing when there is no need for it to?

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" />
<asp:DropDownList id="ddlPager" AutoPostBack="true"
CssClass="ddlPagerDDL"
OnSelectedIndexChanged="ddlPager_SelectedIndexChanged"
Runat="server" /> &nbsp;
<span>
<asp:LinkButton ID="lnkPagerBack" ToolTip="Previous"
runat="server" OnClick="lnkPagerBack_Click"
CssClass="lblPagerArrow" Text=" < " /> &nbsp;
<asp:LinkButton ID="lnkPager" ToolTip="Next"
runat="server" OnClick="lnkPager_Click"
CssClass="lblPagerArrow" Text=" > " /> &nbsp;
</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();
}
 
B

bruce barker

have the onclick return false. though why render/enable the previous
link in the first place if you are on page 1?

-- bruce (sqlwork.com)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,965
Messages
2,570,148
Members
46,710
Latest member
FredricRen

Latest Threads

Top