开发者

ASP.NET DropDownList not refreshing despite DataBind (and showing new data on step thru)

This is my setup: I've got a dropdownlist of people and a linkbutton next to it to add a person. the linkbutton makes an update panel appear. When clicking save, I want the data to be saved and the new person be selected in the dropdown. As far as I can tell, I have done this properly. After I save the data I refresh the dropdownlist and take the new person's value and set it as the selected value. When stepping through, it shows the ddl with the new person and the new person selected! BUT, when the page comes back, the ddl is unchanged, ie NOT refreshed. I thought it might be something with the Update Panel but I got a similar setup to work on another page! It also works on a nested Update Panel (not shown in the following code). Can you think of why this "deception" is happening?

Here is some of my code. Sorry it's so long. Thanks for your help!!

   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" />
  &开发者_如何转开发lt;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>


I had a similar isssue. Fixed it by mannually adding the new listitem to the dropdown instead of rebinding it ...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜