开发者

Timing Issue with AJAX,ASHX, and webform

I have an ASP.NET application and I think I am running into a timing issue. I have a control on a webform开发者_Go百科 that will call some Javascript on the OnClientClick and also call code behind via server-side onClick. I click the button (a print button in my instance) and I call Javascript prompt to enter a reason for the print. I enter whatever and then in the JS I call an ashx (handler) page via AJAX passing the results of the prompt.

The handler then places the Text from the prompt into a session variable. Once the JS is done the OnClick code behind is called calling a method that will grab the reason from the session variable (after the ashx has written it) and log the info and print.

What I am seeing is the very first time I do this I get an error my reason not found (ie. session variable is null). It works every time after that. So, what I believe is happening is the first time the ASHX page is being called, it is being compiled/loaded and not adding info to the session fast enough.

My question is there a clean way to slow down my print function and give the JS call time to complete?


I would remove the serverside onClick and have the onClientClick function post the user's input to where your serverside onClick was going before. Removing the ashx step completely.

If you need the ashx step then I would post the user to the next step in the onComplete event of the ashx ajax call. This will ensure that everything fires in the correct order.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜