Today, UpdatePanel is used in. NET, and the input boxes inside use the jquery calendar selector:
Copy Code code as follows:
<script type= "Text/javascript" >
$ (function () {
$ ("#ctl00_ContentPlaceHolder1_txtDateFrom"). DatePicker ({
Inline:true,
Daynamesmin:["Day", "one", "two", "three", "four", "five", "Six", "],//" is called Chinese
firstday:1,//Weekly starting from Monday
Regionalization month named Chinese custom monthnames:["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
showmonthafteryear:true,//month is displayed after year
Yearsuffix: "Year",//year suffix character
Changeyear:true,
Changemonth:true,
showbuttonpanel:true,//Display button panel
Currenttext: "Today",//The text on the current date button
Closetext: "Off",//close the text on the button
DateFormat: "Yy-mm-dd"
});
}
</script>
Normal after running:
However, after running, click "Query", page local refresh, find calendar selector does not come out, looking for a lot of information, they said:
Analysis 1:updatepanel
UpdatePanel is mainly used for local refresh in the application and avoids the postback of the whole page.
The core of UpdatePanel implementation of local refresh is Microsoftajaxwebform.js file, its local refresh process is to submit the page to the server (including ViewState), Executes the server-side code and asynchronously renders the HTML within the UpdatePanel.
During this process, the rest of the page does not have a status change.
Analysis 2:jquery
jquery can add a variety of properties and event handles to HTML elements with simple code, where we can see official documents:
Tutorials:how JQuery Works
Http://docs.jquery.com/How_jQuery_Works
Here, we can see that jquery has an important event tag "ready", which is generally added to the effects of HTML elements and event handles, as follows:
$ (document). Ready (function () {
$ ("P"). Text ("The DOM is now loaded and can manipulated.");
});
The official explanation for this is that the ready event will run once after the DOM is fully loaded, OK, so the reason for the problem is almost clear:
Reason:
Because the text box elements in the UpdatePanel are rewritten after the local refresh, and the entire DOM tree is not reloaded, the jquery ready event does not trigger, so the text box element loses its original effect.
Solution:
We can extract the code that executes in the Ready event:
Copy Code code as follows:
<script type= "Text/javascript" >
function Showdatepicker () {
$ ("#ctl00_ContentPlaceHolder1_txtDateFrom"). DatePicker ({
Inline:true,
Daynamesmin:["Day", "one", "two", "three", "four", "five", "Six", "],//" is called Chinese
firstday:1,//Weekly starting from Monday
Regionalization month named Chinese custom monthnames:["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
showmonthafteryear:true,//month is displayed after year
Yearsuffix: "Year",//year suffix character
Changeyear:true,
Changemonth:true,
showbuttonpanel:true,//Display button panel
Currenttext: "Today",//The text on the current date button
Closetext: "Off",//close the text on the button
DateFormat: "Yy-mm-dd"
});
}
</script>
This function is also placed in jquery.:
Copy Code code as follows:
<script type= "Text/javascript" >
$ (function () {
Showdatepicker ();
});
</script>
The jquery initialization code is then executed once after each UpdatePanel local flush by capturing the ScriptManager endrequest event, as follows:
Copy Code code as follows:
<script type= "Text/javascript" >
function Load () {
Sys.WebForms.PageRequestManager.getInstance (). Add_endrequest (Endrequesthandler);
}
function Endrequesthandler () {
Showdatepicker ();
}
</script>
Finally, add the load () function in <body>, namely:
Copy Code code as follows:
<body onload= "Load ()" >
This allows jquery code to execute even if the UpdatePanel is partially refreshed.