nullseifer
nullseifer

Reputation: 112

UpdatePanel ASyncPostBack troubles

I am having some problems using UpdatePanels in my C#/ASP.NET application. I shall post my code first, and then explain my problem.

<asp:DropDownList ID="ddlSavedAddresses" runat="server" AutoPostBack="true">
<asp:ListItem Selected="True" Value="">Choose from your saved addresses: </asp:ListItem>
</asp:DropDownList>

<asp:UpdatePanel ID="upnlAddress" runat="server">
<Triggers>
    <asp:AsyncPostBackTrigger ControlID="ddlSavedAddresses" EventName="SelectedIndexChanged" />
</Triggers>
 <ContentTemplate>
 <div>
    <div class="minWidth490 topMargin10">
        <fieldset>
        <div>
            <label for="buildingName">Building Name</label>
        </div>
        <div>
            <asp:Textbox runat="server" id="txtBuildingName" CssClass="short" ToolTip="Enter your house name here" />
        </div>
    </div>
  </ContentTemplate>
</asp:UpdatePanel>

The above is my .ascx file file.

this.ddlSavedAddresses.SelectedIndexChanged += new EventHandler(ddlSavedAddresses_SelectedIndexChanged);

void ddlSavedAddresses_SelectedIndexChanged(object sender, EventArgs e)
{
    // in my code, I have a breakpoint in this method, which is being hit
    this.txtBuildingName.Text = "FOO";
}

My actual code has more fields than this (I'm sure you gathered that) however it is simply more of the same.

As stated above, the event is firing, and any breakpoints I set in the ddlSavedAddresses_SelectedIndexChanged are being hit.

I also put a quickwatch on the .Text value of this.txtBuidlingName and it appears to be "FOO" as expected, however, the actual value of the textbox that the web page has rendered remains blank.

This is my issue. No matter what, the value remains blank. If I fire the event multiple times (by changing the DropDownList's SelectedIndex), it simply fills each field in the with a ',' for every event I fire.

I believe I am being short sighted and this is something miniscule, however, I am at a loss and would greatly appreciate your help.

Upvotes: 3

Views: 907

Answers (2)

daniloquio
daniloquio

Reputation: 3902

Imported from the comments section

  1. Add upnlAddress.Update(); at the end of your SelectedIndexChanged event.
  2. Add UpdateMode="Conditional" to your UpdatePanel definition.

Upvotes: 3

Behnam Esmaili
Behnam Esmaili

Reputation: 5967

it seems that you need call Update method of your updatepanel. try this :

void ddlSavedAddresses_SelectedIndexChanged(object sender, EventArgs e)
{    
    this.txtBuildingName.Text = "FOO";
     upnlAddress.Update();
}

Upvotes: 2

Related Questions