Tuesday, March 27, 2012

list screen is caching

Hi
Ive got an admin screen which has a delete record button - this is working fine - but after clicking the delete the record is then deleted and then a response.redirect("listscreen.aspx") takes them back to the list of records.
However the record that has just been deleted still appears in the list - if you click refresh then the record goes so the listscreen.aspx is caching the record ( users get to the detail screen where they delete the record through the list screen so they it must have been hit before ... )
is there a way to basically say 'always requery the database when loading' ?
thanksThis typically happens to me when I load the control from within a
 Not IsPostBack
conditional... Just move the code to load the list outside of the conditional...
Hi thanks for your reply
I have this as my onload event

Sub Page_Load(Source As Object, E As EventArgs)
If Not Page.IsPostBack Then
BindGrid()
End If
End Sub

do you mean simply to remove the condidtional ( i have tried this and the same thing is happening ...

Sub Page_Load(Source As Object, E As EventArgs)
' If Not Page.IsPostBack Then
BindGrid()
' End If

End Sub

thanks
Yup...

Otherwise you are only binding the grid, querying the data, on the initial page load...
Thanks ...
I have removed the conditional but it is still caching the record just deleted - again , if i refresh the page the record has been removed though ...
So the page is not reposting after the update to the database...

Try putting the conditional back in as it was...

Then call your binding routine right after you run the db update...

I'm assuming that the db update is in response to some event like a button click...
hi
the update ( delete ) is on another page

this is the code for the list screen ...

<%@. Page Language="VB" Debug="true" %
<script runat="server"
Sub Page_Load(Source As Object, E As EventArgs)
If Not Page.IsPostBack Then
BindGrid()
End If

End Sub

Sub bindgrid()
Dim objConnection As OleDbConnection
Dim objAdapter As OleDbDataAdapter
Dim objDataset As DataSet
dim strsql as string
objConnection = New OleDbConnection(getdsn())
'check for a search
if lblSearch.text="" then
strsql="select * from blog"
else

strsql="select * from blog where subject like '%" & replace(lblsearch.text,"'","'") & "%' OR blog like '%" & replace(lblsearch.text,"'","'") & "%'"
end if

objAdapter = New OleDbDataAdapter ( strsql,objConnection)
objDataset = New DataSet()
objAdapter.Fill(objDataset,"blog")
dgresults.DataSource = objDataset.Tables("blog")

dgresults.DataBind

End sub

Sub Page_Change(sender As Object, e As DataGridPageChangedEventArgs)

dgResults.CurrentPageIndex = e.NewPageIndex

BindGrid()

End Sub

Sub searchTable(sender as Object, e as EventArgs)

lblSearch.text=searchterm.text

dgresults.CurrentPageIndex = 0

bindGrid()

End sub

</script
<!-- #include file=dsn.asp --
<html>
<head>
<link rel="stylesheet" type="text/css" href="http://links.10026.com/?link=fontcss.inc" />
<title>blog</title
</head>
<body
<%@. Import Namespace="System.Data" %>
<%@. Import Namespace="System.Data.OleDb" %>
<center>
<table width=80%>
<form runat="server"
<tr><td><a href=default.aspx>blog.mdb menu</a><br><br></td></tr>
<tr><td>
<asp:TextBox id="SearchTerm" runat="server"></asp:TextBox
<asp:button id="Button1" onclick="searchTable" runat="server" Text="search"></asp:button
<asp:Label id="lblSearch" runat="server" visible="false" text="" forecolor="red"></asp:Label>
Searches fields subject,blog
</td></tr
<tr><td>Records in blog<br></td></tr
<tr><td>Insert record into blog<br></td></tr>
<asp:DataGrid id="dgResults" runat="server"
AllowPaging="True"
PageSize="20"
PageCount="1"
PagerStyle-Mode="NumericPages"
PagerStyle-HorizontalAlign="Left"
OnPageIndexChanged="Page_Change"
pagerstyle-position="top"
BorderColor="black"
BorderWidth="1"
GridLines="Both"
CellPadding="3"
CellSpacing="0"
Font-Name="Verdana"
Font-Size="8pt"
HeaderStyle-BackColor=""
AutoGenerateColumns="false"
AllowSorting="True"
HorizontalAlign="center"
width="80%"

<Columns>
<asp:HyperlinkColumn
HeaderText="subject"
DataTextField="subject"
DataNavigateUrlField="blogid"
DataNavigateUrlFormatString=
"blogDetailAdmin.aspx?id={0}"
/>
<asp:HyperlinkColumn
HeaderText="blog"
DataTextField="blog"
DataNavigateUrlField="blogid"
DataNavigateUrlFormatString=
"blogDetailAdmin.aspx?id={0}"
/>
</Columns
</asp:DataGrid>
</form>
</body></html
and this is the code for the detail screen where the record is removed ... it is then response.redirect back to the list screen ...
so I dont know how i can bind the list screen after the delete has happened as it is on a different page - any more ideas ?
thanks again

0 comments:

Post a Comment