Question

So i try to get a value from a async-task (is not shown here because its not relevant i think and it works) into a progressbar over a Jquery-xhr request. The serverside methode is not relevant because its working, and the jquery-xhr-call works also (the first time only).

ASPX-Code:

<script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {
        if (hfworking.Value == "true")
        {
            LabelProgress.Text = hflabel.Value;
            ProgressBar1.Maximum = Convert.ToInt32(hfPBMax.Value);
            ProgressBar1.Value = Convert.ToInt32(hfPBVAL.Value);
        }
    }
</script>
<html>
<head runat="server" id="head1">
<script src="JavaScript.js" type="text/javascript"></script>
<script src="jquery-1.11.0.min.js" type="text/javascript"></script>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager runat="server" ID="pageScriptManager" EnableViewState="true"/>
    <%--<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
        <ContentTemplate>--%>
        <%----%><%--OnClick="Button1_Click"--%>
            <asp:Button runat="server" ID="btnDoTask" Text="Do Task" OnClientClick="StartJavaScriptProgress()" />

            <br />
            <asp:Label ID="LabelProgress" runat="server" EnableViewState="true"></asp:Label>

            <br />
            <eo:ProgressBar ID="ProgressBar1" runat="server" Width="250px" BackgroundImage="00060301"
                BackgroundImageLeft="00060302" BackgroundImageRight="00060303" ControlSkinID="None"
                IndicatorImage="00060304">
            </eo:ProgressBar>
            <asp:HiddenField ID="hflabel" runat="server"/>
            <asp:HiddenField ID="hfPBMax" runat="server"/>
            <asp:HiddenField ID="hfPBVAL" runat="server"/>
            <asp:HiddenField ID="hfworking" runat="server" Value="false" />

My Javascript code in the external Javascript.js:

function StartJavaScriptProgress() {
    try {
        //setTimeout(WebService(), 1000);
        document.getElementById("hflabel").value = "Currently Working ...";
        var intervall = window.setInterval(WebService(intervall), 1000);
    }
    catch (Error) {
        alert(Error.Description + " " + Error.InnerException + " " + Error.StackTrace);
    }
};

function WebService(intervall) {
    try {
        if (document.readyState == 'complete') {

            $.ajax(
    {
        type: "POST",
        url: "AsyncTest.aspx/GetProcess",
        data: "{}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (response) {
            if (response.d.Progressvalue == 'FINISHED') {
                window.clearInterval(intervall);
            }
            else {
                document.getElementById("hfPBMax").value = response.d.Progressmaximum;
                document.getElementById("hfPBVal").value = response.d.Progressvalue;
                document.getElementById("hfworking").value = "true";
                alert("Worked! the maximum is " + response.d.Progressmaximum + " and the actual value is " + response.d.Progressvalue + "!!");
            }
        },
        error: function (response) {
            alert(response.status + " " + response.responseText);
        }
    })
        }
    }
    catch (Error) {
        alert(Error.Description);
    }
};

It allways gives me the error: "Invalid Argument" on the Catch of the SetInterval ... I dont understand why ? Also i dont get the page-lifecycle with this code, it makes the call, goes into the exception and if i have a breakpoint setted to "hfPBMax" it makes it after it went into the exception ? Not even mentioning how often it jumps into Page_Load while it makes no sense for me from what i learned about the asp.net lifecycle ... Would be nice if someone could help me with my missunderstandings and fails.

Was it helpful?

Solution

try this for your interval:

var intervall = window.setInterval(function(){WebService(intervall)}, 1000);

otherwise what you are passing to setInterval is the result of the execution of WebService(intervall), which may not be a function and therefore it will throw an exception

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top