473,421 Members | 1,556 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,421 software developers and data experts.

Refreshing client browsers (with javascript from asp.net code)

I have a page called CustomerSlides.aspx which contains an iframe(with the
source Lookupage.aspx). The iframe page will look continuously in the
database to see if a value has changed: if it is true it will run a java
script dynamically to update the parent page CustomerSlides.aspx.cs.
The value in the Database is changed from another aspx page så all the
changes made in this page will be updated in CustomerSlides.aspx.
I used the code below and it is working as long as it is only one client
looking at CustomerSlides.aspx. If more than one client are looking at the
same page from diffrent browsers(computers) no updates are done. Then have to
refresh manually. I wonder why it is working for one client and not for the
other? Is there any solution? Any help is highly appreciated.
See my code below:
Code behind for(CustomerSlides.aspx.cs):

public class CustomerSlides : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Message;
protected System.Web.UI.HtmlControls.HtmlGenericControl mainIframe;

public string fullPath;

private void Page_Load(object sender, System.EventArgs e)
{

//Get the logged on administrator's email, retrieved from
"signincustomer.aspx.cs"(Will be used in the next step)
// string adminEmail = Convert.ToString(Session["senderAdmin"]);
string adminEmail = "te**@test.se";

//Retrieve the fullPath to the slide to be shown

// Create Instance of Connection and Command Object
SqlConnection myConnection = new
SqlConnection(ConfigurationSettings.AppSettings["connectionString"]);
// SqlCommand myCommand = new
SqlCommand("Portal_GetSlideFullPathFlag2", myConnection);
SqlCommand myCommand = new SqlCommand("SELECT DISTINCT
FullPath FROM TTflag2 WHERE AdminEmail = @AdminEmail ", myConnection);

// Mark the Command as a SPROC
// myCommand.CommandType = CommandType.StoredProcedure;

// Add Parameters to SPROC
SqlParameter parameterAdminEmail = new
SqlParameter("@AdminEmail", SqlDbType.NVarChar, 50);
parameterAdminEmail.Value = adminEmail;
myCommand.Parameters.Add(parameterAdminEmail);
try
{
// Execute the command
myConnection.Open();
SqlDataReader dr =
myCommand.ExecuteReader(CommandBehavior.CloseConne ction);

dr.Read();
fullPath = dr.GetString(0);

dr.Close();
}
catch (Exception ex)
{
Message.Text = ex.Message + " " + ex.StackTrace;
}

if ((fullPath != string.Empty) & (fullPath !=
null))
{
//Find the mainIframe control and add a source attribute
to it
HtmlControl mainIframe =
(HtmlControl)this.FindControl("menuForm").FindCont rol("mainIframe");
mainIframe.Attributes["src"] = fullPath;

}
else
{
HtmlControl mainIframe =
(HtmlControl)this.FindControl("menuForm").FindCont rol("mainIframe");
mainIframe.Attributes["src"] = "MainCustomer.aspx";
}
}

//-------------------------------------------------------------------------------------------------------------------------------------------------------
Code Behind for (LookupPage.aspx.cs):

public class LookupPage : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Message;
public string adminEmail;
private void Page_Load(object sender, System.EventArgs e)
{

//Get the logged on administrator's email(Will be used in the
next step)
// string adminEmail = Convert.ToString(Session["adminEmail"]);
string adminEmail = "te**@test.se";
//************************************************** *******************
//
// This gets the count of the slides in Table TTflag,
// This tell us if we need to refresh CustomerSlides.aspx.
//

//************************************************** *******************

// Create Instance of Connection and Command Object
SqlConnection myConnection = new
SqlConnection(ConfigurationSettings.AppSettings["connectionString"]);
SqlCommand myCommand = new
SqlCommand("Portal_GetSlideInsertFlag2", myConnection);

// Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedure;

// Add Parameters to SPROC
SqlParameter parameterAdminEmail = new
SqlParameter("@AdminEmail", SqlDbType.NVarChar, 50);
parameterAdminEmail.Value = adminEmail;
myCommand.Parameters.Add(parameterAdminEmail);
// myCommand.CommandTimeout = 300;

try
{
// Execute the command
myConnection.Open();

//Get the slide which has been clicked by the
administrator
//from database table TTflag
int myInsert = Convert.ToInt32(myCommand.ExecuteScalar());
ViewState["myInsert"]= myInsert;
}
catch(Exception ex)
{
Message.Text = ex.Message + " " + ex.StackTrace;
}

finally
{
//Close connection
if(myConnection.State != ConnectionState.Closed)
myConnection.Close();
}

//Control if there is a slide in database table TTflag
(inserted by the logged on administrator)
if(Convert.ToInt32(ViewState["myInsert"]) > 1)
{
//Refreshes the actual page
//Add the script to declare the
function
StringBuilder sb = new
StringBuilder("");
sb.Append("<script language =
javascript>");
sb.Append("{");

sb.Append("window.parent.location.reload();");
sb.Append("}");
//Close script
sb.Append("<");
sb.Append("/");
sb.Append("script>");

//Register the script (names
are CASE-SENSITIVE)
// if
(!IsClientScriptBlockRegistered("window.parent.loc ation.reload();"))

RegisterStartupScript("ReloadScript", sb.ToString());

//Delete the slide (inserted by the logged on
administrator) from TTflag
PresentationDB deleteSlideInsert = new PresentationDB();
deleteSlideInsert.DeleteSlideInsertFlag2(adminEmai l);
}

}
Nov 19 '05 #1
0 1056

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Philo Del Middleston | last post by:
I've been searching, but apparently not phrasing my search right, so I'm going to float a question out here in the meantime... I'm wondering how to go about refreshing the content of a control...
4
by: Jamie Jackson | last post by:
The crux of the problem is I only know if the popup *has been* opened, but not if it *is* open. Therefore, the script doesn't know whether to simply refocus, or whether to popup a fresh window. ...
1
by: viktor9990 | last post by:
I have a page called CustomerSlides.aspx which contains an iframe(with the source Lookupage.aspx). The iframe page will look continuously in the database to see if a value has changed: if it is...
1
by: viktor9990 | last post by:
I have a page called CustomerSlides.aspx which contains an iframe(with the source Lookupage.aspx). The iframe page will look continuously in the database to see if a value has changed: if it is...
1
by: Asha | last post by:
greetings, can someone show me how to read a client side value from code behind withouth having to resfresh the page? here is the code i've implemented.... ...
8
by: Doug Lerner | last post by:
I have this snippet of client side code running: var makeField = document.forms; alert("makeFieldName name,length,type=" + makeFieldName + ", " + makeField.name + "," + makeField.length + ","...
10
by: Ben | last post by:
Hi, I made an application in classic asp (reservation of books and video stuffs for students) and want to migrate to asp.net. The user has to chose a date, then pushung on a submit button. The...
4
by: Dan | last post by:
Hi, i'm not sure to understand the difference between refreshing the pagina by clicking on 'refresh' in the browser and a postback. What i think it is: Suppose a page with a form containing a...
2
by: stevemtno | last post by:
I've got a problem with a web page I'm working on. I have 4 modules - one of them has 2 tabs, two of them have 4 tabs. When the user clicks on the tabs, the content below them changes. However, when...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.