Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Refreshing client browsers (with javascript from asp.net code)

Reply
Thread Tools

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

 
 
=?Utf-8?B?dmlrdG9yOTk5MA==?=
Guest
Posts: n/a
 
      02-22-2005
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 = "(E-Mail Removed)";

//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 = "(E-Mail Removed)";


//************************************************** *******************
//
// 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);
}

}
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Browsers, browsers! Quo vadis? El Kabong HTML 23 05-13-2007 08:55 PM
Self-refreshing and non-self-refreshing controls Harlan Messinger ASP .Net 1 08-04-2006 01:13 PM
Self-refreshing and non-self-refreshing controls Harlan Messinger ASP .Net Web Controls 0 08-03-2006 12:29 PM
Two Browsers work! Two browsers won't load. Internet game service won't load jimmie Computer Support 1 02-26-2006 08:36 AM
reading client value from code behind withoout refreshing... =?Utf-8?B?QXNoYQ==?= ASP .Net 1 08-13-2004 04:19 AM



Advertisments