开发者

asp.net postback before page fully loaded cause dropdownlist to have the wrong SelectedValue

We were having occasional reports where the value of a set of DropDownBoxs in a GridView would be reset to the first value item in the list.

We finally tracked it down to a timing issue where a user would click Save before the page finished rendering/loading the data, and we are able to repro it on the production server but not locally because the page loads too quickly.

How would we go about detecting this on the server side to know the data returned is invalid or otherwi开发者_开发百科se stop from setting data that the user didn't set?


thought about enable the save button only if the page is loaded?

another suggestion... does the dropdownlist have an id? i've had some curious issues with dynamically generated controls without an id, returning wrong values after a postback...


I had the same issue. Worked fine locally, but an occasional production user would somehow submit the page with partial form data.

From the logging I could see the HttpRequestFormVariables looked normal up to a point, and then the values became blank, which resulted in the site throwing an unhandled exception.

ctl00$MainContentPlaceHolder$foo$rptForm$ctl01$txtFormFieldId = 3815 ctl00$MainContentPlaceHolder$foo$rptForm$ctl02$txtFormFieldId = 3816 ctl00$MainContentPlaceHolder$foo$rptForm$ctl03$txtFormFieldId = 3817 ctl00$MainContentPlaceHolder$foo$rptForm$ctl04$txtFormFieldId = 3818 ctl00$MainContentPlaceHolder$foo$rptForm$ctl05$txtFormFieldId = ctl00$MainContentPlaceHolder$foo$rptForm$ctl05$txtFormFieldId =

The only way I've been able to reproduce it is to add some Javascript to the page to make it submit before fully loaded.

<script type="text/javascript">
    $("input[id$='btnSubmit']").click();
</script>

I suspect I will need to send btnSubmit back from the server in the disabled state and then enable it from Javascript after the page has completed loading.

if (btnSubmit.Enabled)
{
        btnSubmit.Enabled = false;
        string script = "$(document).ready(function() {$(\"input[id$='" + btnSubmit.ClientID + "']\").removeAttr('disabled');});";
        this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "EnableSubmitButton", script, true);
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜