I have a website that is displaying data from a database and I'm having trouble getting the jQuery widgits to update properly with the other asp.net
objects.
The website structured like this:
[Opt1-DDownList] [Opt2-DDownList] [DateSelectTextBox] [TimeSelectTextBox]
[UpdateProgressText] [jQuery Slider to select time]
[----------------- Table of Data depending on selected options ----------------]
A jQuery DatePicker is attached to the DateSelectTextBox. The four items on top trigger a page update by changing the data displayed in the table. The UpdateProgressText tells the user that the data is loading while the page is being updated.
At first, I had everything in an asp:UpdatePanel
. When I tried to change the TimeSelect's max value, the slider's UI wouldn't update. Even if I tried creating a new jQuery Slider with the new max value in pageLoad()
, which I read is called whenever a piece of the page is loaded.
Then I tried taking out everything out of the asp:UpdatePanel
except for the table. The jQuery slider started updating, but the asp:UpdateProgress
stopped being triggered (probably because the page loading is being triggered by one of the following: (1) one of the Drop Down Lists, (2) Date Select, or (3) Time Select and none of them were in an asp:UpdatePanel
.
Is there a way to make sure the jQuery Slider updates its UI while it's in an asp:UpdatePanel
?
Are there general guidelines to follow when working with jQuery
, javascript
, and asp:UpdatePanel
? I've been looking online and there are a lot of questions on the subject, but I can't find a general guideline or solution that works for me.
Thanks!
Edit: Here is a snippet my code with the "rebinding" fix suggested below to give you an idea of the struct/contents:
<body>
<form id="frm" runat="server">
<asp:ScriptManager runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdateData" runat="server">
<ContentTemplate>
<asp:DropDownList ID="dd1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="RefreshData"></asp:DropDownList>
<asp:DropDownList ID="dd2" runat="server" AutoPostBack="true" OnSelectedIndexChanged="RefreshData"></asp:DropDownList>
Day: <asp:TextBox ID="DaySelect" runat="server" AutoPostBack="true" OnTextChanged="RefreshData"></asp:TextBox>
Time: <asp:TextBox ID="TimeSelect" runat="server" AutoPostBack="true" OnTextChanged="RefreshData"></asp:TextBox>
<table width="850px">
<tr>
<td width="200px"></td>
<td width="450px">
<asp:UpdateProgress ID="LoadingProgress" runat="server" DisplayAfter="500">
<ProgressTemplate>Loading...</ProgressTemplate>
</asp:UpdateProgress>
</td>
<td width="200px">
<div style="width: 200px;" id="sliceControl"></div>
</td>
</tr>
</table>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script type="text/javascript" id="uiscripts">
var sliceIndex = 0;
var sliceControl = $("#sliceControl");
sliceControl.slider({
min: 0,
ticks: 1,
slide: function (event, ui) { OnSelectedSliceChanged(ui.value); },
create: function (event, ui) {
sliceControl.slider("option", "max", "<%=ViewState[maxTicks]%>");
sliceControl.slider("value", "<%=ViewState[currentInterval]%>");
sliceIndex = sliceControl.slider("value");
}
});
function InitWidgits() {
var datePicker = $("#DaySelect");
datePicker.datepicker({});
var now = new Date();
var utc = new Date(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), now.getUTCHours(), now.getUTCMinutes(), now.getUTCSeconds());
var numValidDays = 7;
var millisecondsInADay = 24 * 60 * 60 * 1000;
datePicker.datepicker("option", "minDate", new Date(utc.getTime() - numValidDays * millisecondsInADay));
datePicker.datepicker("option", "maxDate", utc);
try {
sliceControl.slider("destroy");
} catch (e) { }
sliceControl.slider({
min: 0,
ticks: 1,
stop: function (event, ui) { $("#TimeSelect").trigger("onchange", null); },
slide: function (event, ui) { OnSelectedSliceChanged(ui.value); },
create: function (event, ui) {
sliceControl.slider("option", "max", "<%=ViewState[maxTicks]%>");
sliceControl.slider("value", sliceIndex);
}
});
$("#TimeSelect").prop("readonly", "readonly");
$("#DaySelect").prop("readonly", "readonly");
}
$(document).ready(function () {
// bind your jQuery events here initially
InitWidgits();
});
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_endRequest(function () {
// re-bind your jQuery events here
InitWidgits();
});
</script>
[Code for Table of Data]
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>