I want to hide the textboxes in the Updatepanel according to the user's choice in the Combo boxes. It works well outside of the UpdatePanel but it stops working and no longer hiding textboxes when I put inside the UpdatePanel. Could you please help me about this? Thanks.
My Codings are开发者_开发技巧 as follow:
<script language="javascript" type="text/javascript">
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_endRequest(BindControls);
$().ready(function () {
BindControls();
$("#<%= ddlType.ClientID %>").change();
});
function BindControls() {
$("#<%= ddlType.ClientID %>").change(function () {
ShowHideCalendars();
});
}
function ShowHideCalendars() {
$("#trDates").toggle($("#<%= ddlType.ClientID %>").val() == "T1");
}
</script>
<asp:UpdatePanel runat="server">
<contenttemplate>
<asp:DropDownList runat="server" id="ddlType" AutoPostBack="True"
onselectedindexchanged="ddlType_SelectedIndexChanged">
<asp:ListItem>T1</asp:ListItem>
<asp:ListItem>T2</asp:ListItem>
</asp:DropDownList>
<table>
<tr>
<td>Row 1</td>
</tr>
<tr id="trDates">
<td>From: <asp:TextBox ID="TextBox1" runat="server" CssClass="dtpicker"></asp:TextBox> To: <asp:TextBox ID="TextBox2" runat="server" CssClass="dtpicker"></asp:TextBox></td>
</tr>
<tr>
<td><asp:Literal ID="ltStatus" runat="server" Text="You haven't selected."></asp:Literal></td>
</tr>
</table>
</contenttemplate>
</asp:UpdatePanel>
Usually, it's safer to use live() jQuery method when adding handlers for controls inside updatepanel
However, I'm not sure whether it will solve your problem
What happens is as follows - you are toggling the textboxes visibility in the client side, but then a postback occurs. When the textboxes are inside an UpdatePanel, they are being rendered again and that toggling action is lost.
Two things you can do:
1) If you all you are doing when the drop-down value is change is toggling the textbox visibility, you can lose the AutoPostBack="True"
and the OnSelectedIndexChanged
event.
2) If you are doing more than that and need the server side call, you can set the textbox visibility in the server side event.
精彩评论