Problem updating updatepanel containing repeater in custom control with javascript
I am simply trying to update a custom control (which contains a repeater) from a dropdownlist onchange even开发者_如何学Pythont that fires some javascript.
So the dropdownlist and updatepanel are as such:-
<asp:UpdatePanel runat="server" ID="pnlPanelStageBandLetterTemplate" Visible="false" UpdateMode="Conditional">
<ContentTemplate>
<asp:DropDownList runat="server" ID="ddlBand">
<asp:ListItem Selected="True" Text="1" Value="1" />
<asp:ListItem Text="2" Value="2" />
<asp:ListItem Text="3" Value="3" />
<asp:ListItem Text="4" Value="4" />
<asp:ListItem Text="5" Value="5" />
<asp:ListItem Text="6" Value="6" />
</asp:DropDownList>
<panelStageLetters:PanelStageBandLetterTemplate id="psbltPanelStageBandLetterTemplate" runat="server">
</panelStageLetters:PanelStageBandLetterTemplate>
</ContentTemplate>
the dropdown ddlband is rendered with the following:-
ddlBand.Attributes.Add("onchange", "changeCutBand('" + pnlPanelStageBandLetterTemplate.ClientID + "')");
ddlBand.ID = "ddlBand";
when the dropdownlist is selected, it fires the following code:-
function changeCutBand(panelID) {
var cbc = ($(".cutBandChanger")[0]);
val = cbc.value;
var wsid = getQueryVariable('wsid');
if (val != "0") {
$.get("changecutband.ajax?action=changecutband&newcutmethod=" + val + "&wsid=" + wsid);
var panelID = document.getElementById('ctl00_ContentPane_ctl01_pnlPanelStageBandLetterTemplate');
var ddID = document.getElementById('ctl00_ContentPane_ctl01_ddlBand');
__doPostBack(panelID, val);
}
}
this calls some ajax which does a database update from which the data provides the source of the repeater held in the custom control.
My problem is that the database is being updated but the update panel is not being refreshed. All I get is a javascript error saying 'document.getelementbyid <'...'> is null or not an object with an inordinately large line number in the millions.
I spot a few problems in your javascript code:
document.getElementById('ctl00_ContentPane_ctl01_pnlPanelStageBandLetterTemplate')
returns an HTML element, not a string (see the reference: getElementById)__doPostBack
expects two string parameters but you are passing an HTML element as the first one- use
<%: pnlPanelStageBandLetterTemplate.ClientID %>
whereever you can when you want to use your panel's ID - use
'<%: pnlPanelStageBandLetterTemplate.UniqueID %>'
as the first argument to__doPostBack
(don't forget the apostrophes since you want to pass a string)
To see a valid postback call how it is generated by ASP.NET, put this somewhere on your page:
<%: ClientScript.GetPostBackEventReference(pnlPanelStageBandLetterTemplate, "arg") %>
It should render something like this onto your page:
__doPostBack('ctl00$ContentPane$ctl01$pnlPanelStageBandLetterTemplate','arg')
This is probably what you are looking for (except for the hard-coded second parameter).
Try to fix these things and let us know how far you are getting.
Cheers, Oliver
精彩评论