Just nu i M3-nätverket
Gå till innehåll

Refresha flera webbklienter från asp.net


viktor9990

Rekommendera Poster

Jag har en sida (CustomerSlides.aspx) som innehåller en iframe(src: Lookupage.aspx). iframe sidan tittar oavbrutet i databasen för att se om ett visst värde förändrats: Om så är fallet så körs ett java script dynamiskt för att uppdatera modersidan(CustomerSlides.aspx).

Värdet i Databasen ändras från en annan sidan (presentation.aspx) sida så alla ändringar på denna sidan speglas på sidan (CustomerSlides.aspx).

Tanken är att vi presenterar produkter från (presentation.aspx) sida och kunden som befinner sig på (CustomerSlides.aspx) ser precis de produkter vi ser beroende på vilken länk vi är på.

koden nedan funkar så länge en enda webbclient som kollar på (CustomerSlides.aspx). När andra användare är på dena sidan från andra webbläsare så ser de bara den första sida med informationen statiskt i den. Jag undrar varför funkar det för en enda webbklient och inte för de andra? Finns det någon lösning så att flera webbklienter samtidigt kan ta del av info. på (CustomerSlides.aspx)? Tack.

Här är min kod:

 

 

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 = "test@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.CloseConnection);

 

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").FindControl("mainIframe");

mainIframe.Attributes["src"] = fullPath;

 

}

else

{

HtmlControl mainIframe = (HtmlControl)this.FindControl("menuForm").FindControl("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 = "test@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.location.reload();"))

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

 

//Delete the slide (inserted by the logged on administrator) from TTflag

PresentationDB deleteSlideInsert = new PresentationDB();

deleteSlideInsert.DeleteSlideInsertFlag2(adminEmail);

}

 

}

 

Länk till kommentar
Dela på andra webbplatser

Arkiverat

Det här ämnet är nu arkiverat och är stängt för ytterligare svar.

×
×
  • Skapa nytt...