product page has datalist control with paging implemented by gridview control, ProductDetail is the second page with back button which will take the user to the previous page.
The problem is when i go to second page in the datalistcontrol and click back button in productdetail page, even the browser back button dosent work, the previous page is not displayed and gives me "Page not found" Error. Any ideas how to make it work
<input id="Button1" type="button" value="Back to Product List" onclick="javasc ript:history.go (-1)" class ="btn"/>
This is Products.aspx.c s
protected void Page_Load(objec t sender, EventArgs e)
{
if (Request.QueryS tring["p"] != null)
{
CategoryID = c.ToInteger(Req uest.QueryStrin g["p"].ToString());
}
if (!(IsPostBack))
{
DisplayProduct( );
}
}
protected void DisplayProduct( )
{
System.Data.Sql Client.SqlConne ction Con = new System.Data.Sql Client.SqlConne ction();
Con.ConnectionS tring = ConfigurationMa nager.AppSettin gs["ConnectionStri ng"];
System.Data.Sql Client.SqlComma nd Cmd = new System.Data.Sql Client.SqlComma nd();
Cmd.Connection = Con;
Cmd.CommandType = CommandType.Sto redProcedure;
Cmd.Parameters. Add("@CategoryI D", SqlDbType.Int);
Cmd.Parameters["@CategoryI D"].Value = CategoryID;
Con.Open();
Cmd.CommandText = "name";
SqlDataAdapter da = new SqlDataAdapter( Cmd);
DataSet mydt = new DataSet();
da.Fill(mydt);
int nRowCount = mydt.Tables[0].Rows.Count;
int maxrecords = (this.dgPager.C urrentPageIndex * this.dgPager.Pa geSize);
da.Fill(mydt, maxrecords, this.dgPager.Pa geSize, "name");
this.dgPager.Vi rtualItemCount = nRowCount;
this.dgPager.Da taSource = mydt.Tables[1].DefaultView;
this.dgPager.Da taBind();
this.dList.Data Source = mydt.Tables[1].DefaultView;
this.dList.Data Bind();
lblPageIndex.Te xt = this.dgPager.Cu rrentPageIndex. ToString();
Session["PageIndex"] = lblPageIndex.Te xt.Trim();
if (Con.State == ConnectionState .Open)
{
Con.Close();
Cmd = null;
Con = null;
}
}
Thank you, Shilpa.
The problem is when i go to second page in the datalistcontrol and click back button in productdetail page, even the browser back button dosent work, the previous page is not displayed and gives me "Page not found" Error. Any ideas how to make it work
<input id="Button1" type="button" value="Back to Product List" onclick="javasc ript:history.go (-1)" class ="btn"/>
This is Products.aspx.c s
protected void Page_Load(objec t sender, EventArgs e)
{
if (Request.QueryS tring["p"] != null)
{
CategoryID = c.ToInteger(Req uest.QueryStrin g["p"].ToString());
}
if (!(IsPostBack))
{
DisplayProduct( );
}
}
protected void DisplayProduct( )
{
System.Data.Sql Client.SqlConne ction Con = new System.Data.Sql Client.SqlConne ction();
Con.ConnectionS tring = ConfigurationMa nager.AppSettin gs["ConnectionStri ng"];
System.Data.Sql Client.SqlComma nd Cmd = new System.Data.Sql Client.SqlComma nd();
Cmd.Connection = Con;
Cmd.CommandType = CommandType.Sto redProcedure;
Cmd.Parameters. Add("@CategoryI D", SqlDbType.Int);
Cmd.Parameters["@CategoryI D"].Value = CategoryID;
Con.Open();
Cmd.CommandText = "name";
SqlDataAdapter da = new SqlDataAdapter( Cmd);
DataSet mydt = new DataSet();
da.Fill(mydt);
int nRowCount = mydt.Tables[0].Rows.Count;
int maxrecords = (this.dgPager.C urrentPageIndex * this.dgPager.Pa geSize);
da.Fill(mydt, maxrecords, this.dgPager.Pa geSize, "name");
this.dgPager.Vi rtualItemCount = nRowCount;
this.dgPager.Da taSource = mydt.Tables[1].DefaultView;
this.dgPager.Da taBind();
this.dList.Data Source = mydt.Tables[1].DefaultView;
this.dList.Data Bind();
lblPageIndex.Te xt = this.dgPager.Cu rrentPageIndex. ToString();
Session["PageIndex"] = lblPageIndex.Te xt.Trim();
if (Con.State == ConnectionState .Open)
{
Con.Close();
Cmd = null;
Con = null;
}
}
Thank you, Shilpa.
Comment