Gridview keeps adding rows when user causes postback

P

postings

Hi

I have a gridview that has a footer with text fields and an "add"
linkbutton. This footer allows the user to add new rows to the
gridview.

When the user clicks the "add" linkbutton everything works as you would
expect, a record is added to the gridview. The problem is that if the
user causes a post back after adding a record (i.e. hitting refresh or
F5 on the browser) it will add the same record again and again. e.g. If
the user causes 5 postbacks then 5 duplicate records will be entered.

I can stop this behaviour by disabling viewstate on the gridview, but
then the edit functionality of the gridview stops working properly.

Does anybody have any ideas how I can stop this behaviour?
Here's the code:

Protected Sub lnkAdd_Click(ByVal sender As Object, ByVal e As
System.EventArgs)

Page.Validate()

If Page.IsValid Then

'Add record in the database
mygridview.DataBind()

End If

End Sub


Many thanks!

Alex
 
N

Niraj Ranka

Hello,

Referesh or presing F5 is not postback.

Just let us know... u r adding row to grid using... server side or client
side scripting.

Regards
 
P

postings

Oh to add to this:

<FooterTemplate>
<asp:LinkButton ID="lnkAdd" runat="server" CausesValidation="False"
CommandName="Add" OnClick="lnkAdd_Click" Text="Add"></asp:LinkButton>
</FooterTemplate>

Runs the server side code.....

Thanks

Alex
 
P

postings

Hi Niraj

Any luck on this?

Thanks

Alex

Oh to add to this:

<FooterTemplate>
<asp:LinkButton ID="lnkAdd" runat="server" CausesValidation="False"
CommandName="Add" OnClick="lnkAdd_Click" Text="Add"></asp:LinkButton>
</FooterTemplate>

Runs the server side code.....

Thanks

Alex
 

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,745
Messages
2,569,485
Members
44,909
Latest member
DestinyKetoScam

Latest Threads

Top