• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 540
  • Last Modified:

Refresh asp.net page only on browser Refresh button

What I want to do is to disable any kind of postback (button click,button select gridview row) and refresh. And to leave only option to refresh page (and datatable) by clicking refresh button (F5) in browser by user. Idea is to leave data that is loaded on page load until user click refresh button. Code-behind of this page is vb.
Thanks for help.
0
kahvedzic
Asked:
kahvedzic
  • 3
  • 2
1 Solution
 
magedroshdyCommented:
do you want to prevent the user from re-submitting the same form by refreshing the page ?
0
 
kahvedzicAuthor Commented:
I want to prevent duplicate record insertion and new rows in gridview on submit button click, e.g. if I select first row, click on submit button and in the meantime new row is created in datatable that new first row would be inserted in sql table except one that I select.
0
 
EspavoCommented:
You could DataBind() the GridView from the Page_Load event of the page...
If the DataBind() is inside a If Not IsPostBack Then... then it'll only populate the list on the 1st load (or refresh) of the page...
Espavo
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
kahvedzicAuthor Commented:
With this

If Not IsPostBack Then
Session("myDataTable") = myDt
Me.GridView1.DataSource = myDt
Me.GridView1.Attributes.Add("style", "table-layout:dynamic")
Me.GridView1.AutoGenerateColumns = True
Me.GridView1.DataBind()
End If
When I select row and click on submit button it inserts row in sql server,but when I click refresh it inserts row again. Also, when I click refresh in browser or hit F5 gridview is not refreshing at all, data in the gridview persist from the page load and it does not change.
I need to do this
select row without refreshing (my select button is in the gridview cell)
submit row to sql table
then click refresh button in browser or hit F5 key
page is loaded with new data (gridview with new rows).
0
 
EspavoCommented:
Why do you not want to simply write the new record to the DB and then refresh the page automatically?
The best way I have found to prevent the issues you are talking about are:
  1. When you write the record to the DB, first check to see if an identical record exists, and if it does then don't write it.

    Here's how I do this using a  Strongly Typed DataSet:

    IF NOT EXISTS (SELECT sID FROM StockList WHERE (sCode = @sCode) AND (ItemName = @ItemName))
    BEGIN
    INSERT INTO StockList
                             (sCode, ItemName, ItemUnit, Stock, Price, Supplier, SupplierTel)
    VALUES        (@sCode,@ItemName,@ItemUnit,@Stock,@Price,@Supplier,@SupplierTel)
    END
     
  2. Once you've written data to the page then reload (refresh) the page with a Response.Redirect(Request.RawUrl)
Espavo
0
 
kahvedzicAuthor Commented:
I did this
If Not IsPostBack Then
Session("myDataTable") = myDt
Me.GridView1.DataSource = myDt
Me.GridView1.Attributes.Add("style", "table-layout:dynamic")
Me.GridView1.AutoGenerateColumns = True
Me.GridView1.DataBind()
End If
and on submit button at the end add this
Response.Redirect(Request.RawUrl)
after that I add refresh button on my form with same code
Response.Redirect(Request.RawUrl)
now I have just what I want, I refresh page on my refresh button and prevent duplicate record insertion.
Thanks
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now