这是我的设置:我有一个人员下拉列表和旁边的链接按钮来添加一个人。 linkbutton会出现一个更新面板。单击“保存”时,我希望保存数据并在下拉列表中选择新人。据我所知,我已经做好了。保存数据后,我刷新下拉列表并获取新人的值并将其设置为所选值。单步执行时,会显示新人和新人的ddl!但是,当页面返回时,ddl保持不变,即不刷新。我认为它可能是更新面板的东西,但我有一个类似的设置在另一个页面上工作!它也适用于嵌套的更新面板(以下代码中未显示)。你能想到为什么会发生这种“欺骗”吗?
以下是我的一些代码。对不起,这么久了。谢谢你的帮助!!
public void AddRequestor_Click(object sender, ImageClickEventArgs e)
{
pnlNewRequestor.Style.Add("display", "none"); //regular panel
ibSubmitTask.Enabled = true;
ibSubmitTaskCancel.Enabled = true;
if (!((ImageButton)sender).ID.Contains("Cancel"))
{
SaveRequestor();
Functions.BindList(ddlRequestors, "Requestor", "spGetRequestors", true);
string newRequestor = txtRequestorLastName.Text + ", " + txtRequestorFirstName.Text;
ddlRequestors.ClearSelection();
ddlRequestors.Items.FindByText(newRequestor).Selected = true;
}
//ASPX Code
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="ddlRequestors" InitialValue=""
ErrorMessage="*Required" CssClass="ErrorText" ValidationGroup="valNewTask" Display="Dynamic" runat="server" />
<asp:LinkButton ID="LinkButton1" Text="Add New Requestor" CssClass="SmallerText" OnClientClick="NoPopup();" OnClick="NewRequestor_Click" runat="server"></asp:LinkButton>
</td>
</tr>
<!-- Add New Requestor Update Panel -->
<tr id="tr1" class="HideXXX" runat="server">
<td></td>
<td colspan="2" class="LeftPadding">
<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
<ContentTemplate>
<asp:Panel ID="Panel1" CssClass="AddNewPanel Hide" runat="server">
<table width="100%">
<tr>
<td class="SectionTitle" colspan="3"><asp:Label ID="Label1" Text="Add New Requestor" runat="server"></asp:Label>
<hr class="hrSectionTitle" />
</td>
</tr>
<tr id="tr2" class="Hide" runat="server">
<td></td>
<td class="LeftPadding"><asp:Label ID="Label2" CssClass="ErrorTextLarge" runat="server"></asp:Label></td>
</tr>
<tr>
<td><asp:Label ID="Label3" Text="First Name:" runat="server"></asp:Label> </td>
<td><asp:TextBox ID="TextBox1" CssClass="TextBox DefaultFont" OnFocus="this.className='TextBoxFocus DefaultFont'" onBlur="this.className='TextBox DefaultFont'" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" ControlToValidate="txtRequestorFirstName"
ErrorMessage="*Required" CssClass="ErrorText" ValidationGroup="valNewRequestor" Display="Dynamic" runat="server" />
</td>
</tr>
<tr>
<td><asp:Label ID="Label4" Text="Last Name:" runat="server"></asp:Label> </td>
<td><asp:TextBox ID="TextBox2" CssClass="TextBox DefaultFont" OnFocus="this.className='TextBoxFocus DefaultFont'" onBlur="this.className='TextBox DefaultFont'" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" ControlToValidate="txtRequestorLastName"
ErrorMessage="*Required" CssClass="ErrorText" ValidationGroup="valNewRequestor" Display="Dynamic" runat="server" />
</td>
</tr>
<tr>
<td></td>
<td colspan="2">
<asp:ImageButton ID="ImageButton1" ImageUrl="~/Images/Button-AddRequestor.jpg" CausesValidation="true" ValidationGroup="valNewRequestor" OnClientClick="NoPopup();" OnClick="AddRequestor_Click" runat="server" />
<asp:ImageButton ID="ImageButton2" ImageUrl="~/Images/Button-Cancel-Darker.jpg" CausesValidation="false" OnClientClick="NoPopup();" OnClick="AddRequestor_Click" runat="server" />
</td>
</tr>
</table>
</asp:Panel>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="lbNewRequestor" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="ibAddRequestor" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="ibAddRequestorCancel" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
</td>
</tr>
答案 0 :(得分:0)
我有类似的问题。通过手动将新的listitem添加到下拉列表而不是重新绑定它来修复它...