Refresh an open web page when a button on another open web page is clicked.

Last Reply 8 days ago By dharmendr

Posted 8 days ago

I'm attempting to have an open web page (DISPLAY page) automatically refresh the whenever a button on another open page (CREATE page) is clicked.

To achieve this, I tried to create a global flag of type public static int that will change value to 1 whenever the CREATE page's button is clicked.

//CREATE page page load event handler
protected void Page_Load(object sender, EventArgs e)
        {
            globals.CREATEClickFlag = 0;//reset the CREATE click flag upon page reload
        }

The flag's value will revert back to it's original value of 0 when the DISPLAY page refreshes.

//DISPLAY page page load event handler
protected void Page_Load(object sender, EventArgs e)
        {
            globals.CREATEClickFlag = 0;//reset the CREATE click flag upon page reload
            globals.CREATEClickFlag = 0;//reset the EDIT Click flag when the page loads
        }

I then have a timer element on the DISPLAY page that ticks every second to update the value of the flag. The updated value is stored in the value tag of a hidden input html element.

<!--HTML elements in DISPLAY page-->
<asp:Timer ID="Timer1" runat="server" EnableViewState="False" Interval="1000" OnTick="Timer1_Tick"></asp:Timer>
<input  type="hidden" runat='server' id="CREATEClickFlagHE" value="" />
<input  type="hidden" runat='server' id="EDITClickFlagHE" value="" />
protected void Timer1_Tick(object sender, EventArgs e)
        {
            CREATEClickFlagHE.Value = globals.CREATEClickFlag.ToString();
            EDITClickFlagHE.Value = globals.EDITClickFlag.ToString();
        }

This hidden element is used in an event listener js function

<script type="text/javascript">
            document.getElementById("CREATEClickFlagHE").addEventListener("change", function () {
                if (this.value == "1") { location.reload();}
            })
            document.getElementById("EDITClickFlagHE").addEventListener("change", function () {
                if (this.value == "1") { location.reload(); }
            })
        </script>

However I get a compile error that a ScriptManager is required before the Timer element in html when I try to build the solution. How do I configure the ScriptManager for this purpose to ensure the refresh on click works?

Alternatively, is there a more efficient & less convoluted way of refreshing the DISPLAY page when a button on the CREATE page is clicked?

You are viewing reply posted by: dharmendr 8 days ago.
I agree, here is the link: http://e-iceblue.com/free-api