Search code examples
c#javascriptasp.netresponse

Button Not Working Without Refreshing Page


I am building a website with some simple functions and I'm running into some issues. I can't provided any sample code because I have no idea where the problem lies and technically the site is not crashing.

The frontend of the site is html and javascript, the backend I'm using ASP.Net and C#.

There's a button on the page, which will trigger a function in javascript. The function will then make a call to the backend aspx file (say, myFunction.aspx) and generate a output file for the user to download.

Everything is working just fine. I was getting the expected result and was able to download the output file with no problem.

I didn't notice the issue until I try to re-run this function.

I hit the button again but it wasn't doing anything (I was also using Httpfox so I know it's not calling anything)

I realize that I wasn't able to run the function again without refreshing the page. After refreshing the page it works just fine.

Can anyone explain why its this way? How can I go about debugging this issue? I don't even know if the problem is with the fontend or the backend.

Thanks for the help.

EDIT

This is how I created the button.

<button dojoType="dijit.form.Button" type="button" onclick ="myJSFunction('uploadForm')">Generate</button>

and this is how the function is calling the asp backend

var myJSFunction= function (formId) {
    dojo.io.iframe.send
    ({
        url: 'myURL/myFunction.aspx?parameter=p',
        form: dojo.byId(formId),
        method: "POST",
        handleAs: "text",
        load: function (response, ioArgs) {
            dojo.byId("timeStamp").value = response;
        }
        error: function (response, ioArgs) {
            alert("Failure:" + response);
        }
    });
}

EDIT 2

I just notice something interesting.

I have been running in Firefox using HttpFox and was not getting any error message. Then I tried to run it in Chrome using F12 and I'm getting red alerts.

In Chrome, under the Network tab, the status says "canceled", but I was still getting the output.

How could this happen? How can I find where the issue is?


Solution

  • Thank you all for the help and suggestion.

    I have found the solution to the issue. All I need is a single line to the frontend code.

    dojo.io.iframe._currentDfd = null; //add this line
    dojo.io.iframe.send
    ({...
    });
    

    Thanks for the help.