Refreshing a .aspx... again

Fiasco

New Member
Ok here is my problem.<BR><BR>When my user add a row to a datagrid, it do a postback on the page and triger and event. I do not use post back, but the user click on a linkbutton.<BR><BR>But if the user hit F5 or refresh to page, it add the row again.<BR><BR>Is there a way to empty the "memory" so it call the addrow sub only the first time ?hi,<BR><BR>r u using "Page.IsPostBack"?<BR><BR>regards<BR>yesuYes but how can I know if it is a postback because of button click, or a post back because of browser refresh ?hi,<BR><BR>or else do one thing, put one hidden box and onlclick of the button set hidden value as "true",and do the button click work,<BR>after finishes all the button click work, again set the hidden value to "false"<BR><BR>if flag is "false" it is from browser refresh <BR><BR>hope this will help u.<BR>regards<BR>yesuI thought of this, but since the user can click again on another button, let's say after adding a row, he need to add another one, then the code will think it is a refresh when in fact it is another command.<BR><BR>I will never know when the button work is done, so I won't be able to implement this that way.<BR><BR>What I was looking for is a way to clear the "command cache" or whatever it is called.yeah, i tested here..<BR>that is use less,<BR><BR> Using session u can control,but agian one time it will help.when the next it the user wants add some value it will not work.<BR><BR>I have one more suggesstion<BR> can u check in the datatable before inserting the row?<BR> whether the values are already exists or not in the data table.<BR>I don't know whether it will help u :):)<BR>regards<BR>yesuI've followed the posts on this and have tried to duplicate the problem with sample code. I load the datagrid from the database and open a blank row in the datagrid for user entry. The user clicks on a link to confirm entry and close the edit mode of the datagrid. I save the datagrid as an xml string to viewstate between trips to the server so I don't have to keep opening the database to refresh.<BR><BR>I tried making an entry, hitting the edit link, then hitting refresh. I did not get a duplicate entry.<BR><BR>Since you didn't post code, I can directly compare what you are doing with what I did.<BR><BR>I'll post the code if you are still looking for ideas.<BR><BR>Good LuckHere is the code that add the row:<BR><code><BR> Sub AddPost(sender As Object, e As EventArgs)<BR> Dim TheNewRow as DataRow = Application("ForumDS").Tables("Post").NewRow<BR> Dim RowID as Integer = Application("ForumDS").Tables("ForumList").Rows(0).Item("frmPostCount") + 1 <BR> Dim FatherRow() as DataRow<BR> Dim curForum as Integer = Request.QueryString("forum")<BR> Dim curTopic as Integer = Request.QueryString("topic")<BR><BR> 'Create the new post<BR> TheNewRow("ID") = RowID<BR> TheNewRow("pstText") = txtPostText.Text<BR> TheNewRow("pstCreation") = DateTime.UtcNow().AddHours(-4)<BR> TheNewRow("pstCreator") = Session("UserInfo")("mbrNick")<BR> TheNewRow("pstName") = txtPostName.Text<BR><BR> 'Add it to the DS<BR> TheNewRow = Application("ForumDS").Tables("Post").Rows.Add(TheNewRow)<BR> FatherRow = Application("ForumDS").Tables("Topic").Select("ID='" & curTopic & "'")<BR> Application("ForumDS").Tables("Post").Select("ID='" & RowID & "'")(0).SetParentRow(FatherRow(0), _ <BR> Application("ForumDS").Relations("Topic_Post"))<BR> Application("ForumDS").Tables("ForumList").Rows(0).Item("frmPostCount") += 1<BR><BR> 'Update the other tables<BR> Application("ForumDS").Tables("Forum").Select("ID=" & curForum)(0).Item("frmLastPost") = RowID<BR> Application("ForumDS").Tables("Topic").Select("ID=" & curTopic)(0).Item("tpcLastPost") = RowID<BR> Application("MemberDS").Tables("Member").Select("ID=" & Session("UserInfo")("ID"))(0).Item("mbrNbPost") += 1<BR><BR> Application("MemberDS").AcceptChanges()<BR> Application("MemberDS").WriteXml(Server.MapPath("Member.xml"))<BR> Application("ForumDS").AcceptChanges()<BR> Application("ForumDS").WriteXml(Server.MapPath("Forum.xml"))<BR> <BR> ctrlAddPost.Visible="false"<BR> BindTheData(CreateDataSet())<BR><BR> End Sub<BR></code><BR><BR>The only unique field is the ID but since it is determined when I add the row, I have no way to check if the specific row as been added.&nbsp;<BR>If you explicitly clear the textboxes at the end of your AddRow sub<BR><BR>txtPostText.text = ""<BR>txtPostName.text = ""<BR><BR>Then add some conditional logic at the beginning of the AddRow sub<BR><BR>If txtPostText = "" and txtPostName = "" then exit sub<BR><BR>It seems like any attempt to click either the submit link or refresh without actually making new textbox entries would cause the AddRow sub to be abandoned prior to duplicating a row.<BR><BR>I'm still puzzled at the cause of this since I couldn't duplicate it.<BR><BR>Good Luck
 
Back
Top