SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2005
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Trying to call button click via timer

    Basically, after a certain time period of inactivity, I was to save/update some data via a routine in my ASP.NET code behind file (essentially mimic a button click right before the user's session time's out).

    I'm trying the following and get a javascript error about the object doesn't support this proptery or method..I'm assuming it's for the "myHiddenButton.OnClick();" line of code

    *****

    HTML

    ******

    </head>

    <!-- Start timeout code -->

    <body onmousedown = "window_activity()" onkeypress="window_activity()">

    <script type="text/javascript">

    var timerPROMPT = 0;

    var timerCLOSE = 0;

    function EndApp(){

    //RateDeck.style.display = "none"

    //spDeck.style.display = "none"

    }

    function StopTiming(){

    if(timerPROMPT > 0)

    window.clearTimeout(timerPROMPT)

    //call button

    var myHiddenButton = document.getElementById("myHiddenButtonID");

    myHiddenButton.OnClick();

    //end button call

    if (confirm('Due to inactivity, your session is about to time out.')== 1)

    {

    if(timerCLOSE > 0)

    window.clearTimeout(timerCLOSE)

    timerPROMPT = window.setTimeout("StopTiming()",5000);

    timerCLOSE = window.setTimeout("EndApp()",8000);

    }

    else

    {

    EndApp();

    }

    }

    function window_activity() {

    if(timerPROMPT > 0)

    window.clearTimeout(timerPROMPT)

    if(timerCLOSE > 0)

    window.clearTimeout(timerCLOSE)

    timerPROMPT = window.setTimeout("StopTiming()",5000);

    timerCLOSE = window.setTimeout("EndApp()",6000);

    }

    </script>

    <!-- End timout code -->

    <form id="form1" runat="server">

    <asp:ScriptManager ID="ScriptManager1" runat="server" />

    <div>

    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

    <asp:Button ID="myHiddenButtonID" runat="server" Font-Size="XX-Small" OnClick="myHiddenButtonID_Click"

    Text="Hide" /><br />

    <br />

    <br />


    <asp:Image ID="Image1" runat="server" ImageUrl="~/images/top.jpg" />

    </div>

    </form>

    </body>

    </html>



    *****

    Code behind

    ****

    protected void myHiddenButtonID_Click(object sender, EventArgs e)

    {

    Response.Write("Hidden button click event!");

    }

  2. #2
    SitePoint Evangelist
    Join Date
    Jul 2007
    Posts
    345
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are JavaScript event handlers case sensitive?
    Try myHiddenButton.onclick();

  3. #3
    SitePoint Enthusiast
    Join Date
    Aug 2005
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile Here's what I got to work

    <!-- Start timeout code -->
    <body onmousedown = "window_activity()" onkeypress="window_activity()">
    <script type="text/javascript">
    var timerPROMPT = 0;
    var timerCLOSE = 0;

    function EndApp(){
    //RateDeck.style.display = "none"
    //spDeck.style.display = "none"
    }
    function StopTiming(){

    if(timerPROMPT > 0)
    window.clearTimeout(timerPROMPT)
    //call button
    var myHiddenButton = document.getElementById("btnUpdate");
    myHiddenButton.click();
    //end button call
    //if (confirm('Due to inactivity, your session is about to time out.')== 1)
    //{
    //if(timerCLOSE > 0)
    //window.clearTimeout(timerCLOSE)

    //timerPROMPT = window.setTimeout("StopTiming()",5000);
    //timerCLOSE = window.setTimeout("EndApp()",8000);

    //}
    //else
    //{
    //EndApp();
    //}
    }
    function window_activity() {
    if(timerPROMPT > 0)
    window.clearTimeout(timerPROMPT)
    if(timerCLOSE > 0)
    window.clearTimeout(timerCLOSE)

    timerPROMPT = window.setTimeout("StopTiming()",1080000);
    timerCLOSE = window.setTimeout("EndApp()",1085000);
    }
    </script>
    <!-- End timout code -->


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •