473,325 Members | 2,608 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

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

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_SelectedIndexChan ged"
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();
}

Jun 22 '07 #1
1 2578
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)

mark4asp wrote:
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_SelectedIndexChan ged"
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();
}
Jun 22 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: brendan | last post by:
Sorry this isnt a cross post .. i just didnt get any help from alt.php. I have a website which utilises post forms for navigation in some areas. Problem is, when *some* users hit the BACK button...
45
by: StopThisAdvertising | last post by:
Hi there, We all know Steve Santos. He *really* is an advertising and job-hunting machine. A lot of us have asked him *many* times and in different ways to stop his blatant advertising. This has...
7
by: Denise | last post by:
I just realized the DataTable_RowChanging events were firing when I called Fill method of the DataAdapter! It fires TWICE for each row loaded. I thought these were only supposed to be called when...
3
by: Tom | last post by:
When using system.timers.timer, which should one use to start/stop the timer? Start/Stop, or Enabled=True/False? If what I read is true, both really do the same thing, so I don't know if there is...
1
by: Rajani | last post by:
Hi, I have designed a form which process database Insert, edit and Delete(datagrid). I input userid,password and privilege in textboxes which has validation controls to verify data keyed in....
2
by: Rajani | last post by:
Hi, I have designed a form which process database Insert, edit and Delete(datagrid). I input userid,password and privilege in textboxes which has validation controls to verify data keyed in....
3
by: mark4asp | last post by:
How can I stop my Calendar control from firing the form validation events? I have a form containing several controls which have several validation controls each. One control is a TextBox...
7
by: Daniele Piccinini | last post by:
Hallo, I've writed a C# windows service in VS 2003. This service use a System.Timers.Timer to periodically call some functions of a web service. ( Some of this functions required minutes to be...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.