Wednesday, March 28, 2012

Ajax update panel and the drop down list

Hi all,

Im using the update panel but have got into a spot of bother.

I've used the update panel many times before with buttons, but this time i need to use an update panel so that when a drop down list has its index chasnged that certain panels are shown and certain panels are hidden.

The problem i'm encountering is that the page does the post back, ive tried various options and tried to find decent examples on the next but everything is either with a checkbox or using a button.

on my page.aspx.cs i have the

1protected void dropTaxCertType_SelectedIndexChanged(object s, EventArgs e) {23UpdateCertView();45//UpdatePanel1.Update();6}78protected void UpdateCertView() {910//SortedList answers = this.AnsweredQuestions;11//DropDownList ddl = (DropDownList)sender;12//answers[ddl.ToolTip] = ddl.SelectedValue;13//this.AnsweredQuestions = answers;1415if (dropTaxCertType.SelectedValue =="0") {16pnlCert.Visible =false;17pnlRefNo.Visible =false;18}19else if (dropTaxCertType.SelectedValue =="1000") {20pnlRefNo.Visible =true;21pnlCert.Visible =false;22}23else if (dropTaxCertType.SelectedValue =="n/a") {24pnlRefNo.Visible =false;25pnlCert.Visible =false;26}27else {28pnlCert.Visible =true;29pnlRefNo.Visible =false;30}3132//if (ScriptManager1.IsInAsyncPostBack ){33// string callbackString = Map1.CallbackResults.ToString()34// ScriptManager1.RegisterDataItem(Map1, callbackString)35//}36}
 
as you can see from the above code ive tried various optinos from seeing it on the web with no success.
At first i created my updatepanle and inserted the ddl into it, but i kept getting this javasript error saying ambigous match found.
 
so i put the ddl outside the update panel, but because i have the autopostback it keeps posting back like a normal page without
update panel, but if i take out the autopostback the panls that are supposed to change dont. 
 
<table class="tLayout5"><tr class="top"><td colspan="2"><br /><hr /><br /><br /><strong>CIS Tax Certificate Type:</strong><br /><asp:DropDownList ID="dropTaxCertType" OnSelectedIndexChanged="dropTaxCertType_SelectedIndexChanged" AutoPostBack="true" CssClass="frmWidth99" runat="server"><asp:ListItem Text="" Value="0"></asp:ListItem><asp:ListItem Text="Subcontractor Certifying Document" Value="1000"></asp:ListItem><asp:ListItem Text="CIS4 - Registration card - must pay net" Value="CIS4"></asp:ListItem><asp:ListItem Text="CIS5 - Corporate certificate - can pay gross" Value="CIS5"></asp:ListItem><asp:ListItem Text="CIS6 - Photocard certificate - can pay gross" Value="CIS6"></asp:ListItem><asp:ListItem Text="CIS65 - Temporary registration - must pay net" Value="CIS65"></asp:ListItem><asp:ListItem Text="Exempt or Non Applicable" Value="n/a"></asp:ListItem></asp:DropDownList><br /></td></tr></table><asp:UpdatePanel ID="UpdatePanel1" updatemode="conditional" runat="server"><ContentTemplate><asp:Panel ID="pnlRefNo" runat="server"><table class="tLayout5"><tr class="top"><td colspan="2"><label for="txtUniqueRefNo"><strong>Unique Reference Number:</strong></label><br /><asp:textbox id="txtUniqueRefNo" MaxLength="30" runat="server" CssClass="frmWidth99" /></td></tr></table></asp:Panel><asp:Panel ID="pnlCert" runat="server"><table class="tLayout5"><tr class="top"><td colspan="2"><label for="txtOtherTaxCertType"><strong>Other:</strong></label><br /><asp:textbox id="txtOtherTaxCertType" MaxLength="30" runat="server" CssClass="frmWidth99" /></td></tr><tr class="top"><td style="width:49%;"><label for="txtTaxCertNr"><strong>CIS Tax Certificate Number:</strong></label> <br /><asp:textbox id="txtTaxCertNr" MaxLength="50" runat="server" CssClass="frmWidth99" /><asp:RegularExpressionValidator ID="RegularExpressionValidator7" Enabled="true" ControlToValidate="txtTaxCertNr" Display="Dynamic" runat="server" Text="Invalid Number" ValidationExpression="\w{1,20}" /></td><td style="width:49%;"><label for="radDate_dateInput_TextBox"><strong>Expiry Date:</strong></label>(dd/mm/yyyy)<radcln:raddatepicker id="radDate" MinDate="1980-01-01" AllowEmpty="true" Runat="server"><PopupButton style="float: left" /><DateInput DisplayPromptChar="_" PromptChar=" " onclick="ToggleStartDatePopup()" Width="100px" style="float: left" /></radcln:raddatepicker><asp:RequiredFieldValidator runat="server" ID="rfvDate" ControlToValidate="radDate" InitialValue="1980-01-01" Text="Required!" /><br /></td></tr></table></asp:Panel><Triggers> <asp:AsyncPostBackTrigger ControlID="dropTaxCertType" /> </Triggers></ContentTemplate></asp:UpdatePanel>
 I hope someone can help me pleaseeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
 
many thanxz in advance
 
Zal
 
 
 
Try with the triggers tags outside the contentTemplate tags.

I've tried your code without this lines:

<radcln:raddatepicker id="radDate" MinDate="1980-01-01" AllowEmpty="true" Runat="server">
<PopupButton style="float: left" />
<DateInput DisplayPromptChar="_" PromptChar=" " onclick="ToggleStartDatePopup()" Width="100px" style="float: left" />
</radcln:raddatepicker>
<asp:RequiredFieldValidator runat="server" ID="rfvDate" ControlToValidate="radDate" InitialValue="1980-01-01" Text="Required!" />

with DropDownList inside UpdatePanel, and works fine.


That was probably because you aren't using the RadCalendar when you tried that code or it wasn't set up the same. The drop down wasn't triggering the update outside the update panel because the trigger tags need to be at the same level at the content template tags, not nested.

No comments:

Post a Comment