I have to refresh the page all time

Posted by Satiss7pwr under ASP.NET on 1/20/2010 | Views : 2477 | Status : [Member] | Replies : 8
hi,i am have wbapplication in wich there so many web pages.My problem is that when i do a changes to a page and run the application and go to that page i have to refresh that page expicitly,every time i have to refresh that page.And also i got the value of previos data on that page ,i got the new data when i refresh the page.
i hope u all understand what i want to say.
thanks in advance




Responses

Posted by: Vuyiswamb on: 1/20/2010 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
I understand what you are saying but now my problem is that is your statement

Satiss7pwr wrote


when i do a changes to a page and run the application and go to that page i have to refresh that page expicitly,every time i have to refresh that page.And also i got the value of previos data on that page


Now please Tell us which control are you using to Bind your Data, and when you say old Data , give us more info on your problem. and again you wrote


Satiss7pwr wrote

And also i got the value of previos data on that page ,i got the new data when i refresh the page.

Am not sure what you are doing because you are not suppose to get old data or you closed your application and open it again. PLease share your code with us and let us see how you page your data and how you handle things on page load.

Thank you for posting at Dotnetfunda

Vuyiswa Maseko

Thank you for posting at Dotnetfunda
[Administrator]

Satiss7pwr, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Satiss7pwr on: 1/20/2010 [Member] Starter

Up
0
Down
im using the controls like label,panel,gridview,treeview,dropdownlist etc.
and i got the value of data which i see at last time on appication,when i refesh page i got the value that i needed
thanks for reply

Satiss7pwr, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nishithraj on: 1/20/2010 [Member] Bronze

Up
0
Down
You can either submit the page to the same page or you can reload the page.

Both are possible through Javascript as follows.

1) Sumbitting to the same page.

document.forms[0].action = 'name of the same page';

document.forms[0].submit();


2) Reloading the page.

self.location.reload() ;


Mark this as answer, if it is.....

With regards
Nishithraj Narayanan

Satiss7pwr, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 1/20/2010 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
Nishithraj refreshing the page is not a Good way to go, there is a problem here. e.g i cant bind my data source to the grid and stop my app and start it , and it still show old data. Its not right , instead of suppressing the problem by forcing a post back its better he fix the problem permanently.

Thank you for posting at dotnetfunda

Vuyiswa Maseko

Thank you for posting at Dotnetfunda
[Administrator]

Satiss7pwr, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 1/20/2010 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
can i see the code that you use to bind this control that shows you stale data ?


Thank you for posting at dotnetfunda



Thank you for posting at Dotnetfunda
[Administrator]

Satiss7pwr, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nishithraj on: 1/21/2010 [Member] Bronze

Up
0
Down
Vuyiswamb...That's correct and I agree with you.

But in certain scenario we may require to submit to the same page with the query string. In that case a page post back is required. Unless we should use AJAX to avoid it.

That's the reason I provided that answer.

Also If the person who raised the question has the necessary of auto refreshing a page after a particular time(Like the cricinfo websites), he/she can use the reload option.

As of now He/She has not provided the source code.

Therefore with the limited information I provided the two solutions...

Refreshing a page is not a good way, this basic thing is obvious... the person who raised this question might be knowing the same. So he/She should implement the solutions as per their requirement.

Mark this as answer, if it is.....

With regards
Nishithraj Narayanan

Satiss7pwr, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Satiss7pwr on: 1/21/2010 [Member] Starter

Up
0
Down
for example this my soimple page that on page load fill text box from databse,i have to refresh all time the page.i got always old value of text box,this is code
protected void Page_Load(object sender, EventArgs e)
{

if (!IsPostBack)
{
OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=D:\\PMDS\\App_Data\\Doc_App.mdb;");
OleDbCommand cmd = new OleDbCommand("Select Member_ID,Member_Name,Email_ID from Member_Master where Member_ID=" + Session["mid"] + " ", con);
OleDbDataReader dr;
con.Open();
dr = cmd.ExecuteReader();

while (dr.Read())
{

txtmid.Text = dr.GetInt32(0).ToString();
txtmname.Text = dr.GetString(1);
eid.Text = dr.GetString(2);
}
//Response.Redirect("AllProject.aspx");
con.Close();
}

}

Satiss7pwr, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 1/21/2010 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
First when you post a Code, there is a Toolbar that allow you to format the code. Now the problem here is that your code is screaming please Satiss7pwr put me in a function.


private void Bind_Controls()
{
OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=D:\\PMDS\\App_Data\\Doc_App.mdb;");
OleDbCommand cmd = new OleDbCommand("Select Member_ID,Member_Name,Email_ID from Member_Master where Member_ID=" + Session["mid"] + " ", con);
OleDbDataReader dr;
con.Open();
dr = cmd.ExecuteReader();

while (dr.Read())
{

txtmid.Text = dr.GetInt32(0).ToString();
txtmname.Text = dr.GetString(1);
eid.Text = dr.GetString(2);
}
//Response.Redirect("AllProject.aspx");
con.Close();
}
}


in the page load you will have this

protected void Page_Load(object sender, EventArgs e)
{

if (!Page.IsPostBack)
{
Bind_Controls();

}
}



Now if the Page is not postback that function will not be fired. That means there must be a button or any control that you use to Update the Data, after updating the Data add the function

Bind_Controls();


at the end and set your controls's "Autopostback" Property to true and the Problem will be gone.

Thank you for posting at dotnetfunda

Vuyiswa Maseko

Thank you for posting at Dotnetfunda
[Administrator]

Satiss7pwr, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response