Woland
Woland

Reputation: 1070

updatepanel problem or possible bug

I have TextBox (multiline) and Label in an UpdatePanel which I refresh with javascript __doPostBack(upEditReminder,id);

Then I set both Label and TextBox text to current DateTime.

protected void upReminder_Onload(object sender, EventArgs e)
{
    lbTest.Text = DateTime.Now.ToString();
    tbReminder.Text = DateTime.Now.ToString();

Problem is that Label is updated but TextBox date is updated only once when the page is loaded but not when __doPostBack(upEditReminder,id); is triggered. I cant figure out what the problem is.

I have also tried textarea runat="server" but still have the same problem.

Your help is much appreciated.

Upvotes: 3

Views: 696

Answers (5)

Prutswonder
Prutswonder

Reputation: 10064

From one of your comments I noticed that you are trying to update a textbox outside of the updatepanel. The problem here is that you cannot update something outside the updatepanel in the updatepanel's postback. That's one of the drawbacks of using an updatepanel.

If you still want to use an updatepanel, I suggest that you update the other page's elements using javascript and preferrable jQuery after the updatepanel reload. You could use a hidden input field inside the updatepanel to transfer the data. To refresh the textbox after the update, you could use this JavaScript/jQuery code:

Sys.WebForms.PageRequestManager.getInstance().add_endRequest(function () { 
    var reminder = $("[id$='hidReminder']").val();
    $("[id$='tbReminder']").val(reminder);
});

Upvotes: 0

Raj Kaimal
Raj Kaimal

Reputation: 8304

Add a button inside the UpdatePanel. Click the button, does it update both label and textbox?

In addition, the call you are making should have the ClientID of the updatepanel which looks something like this:

__doPostBack("ctrl00_ctrl01_upEditReminder",'');

Upvotes: 0

Rudism
Rudism

Reputation: 1655

This worked for me... is it different from what you're doing?

aspx code snippet:

<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" OnLoad="UpdatePanel">
    <ContentTemplate>
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
        <asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine"></asp:TextBox>
    </ContentTemplate>
</asp:UpdatePanel>
<a href="#" onclick="__doPostBack('UpdatePanel1','');">Update</a>

codebehind snippet:

protected void UpdatePanel(object sender, EventArgs e)
{
    Label1.Text = DateTime.Now.ToString();
    TextBox1.Text = DateTime.Now.ToString();
}

Clicking the "Update" link triggers the UpdatePanel's postback which refreshes it via ajax and both the label and textarea get the updated timestamp.

Upvotes: 3

Paddy
Paddy

Reputation: 33857

Are you setting the textbox text anywhere else in your code behind? I'm guessing it's getting overwritten somewhere...

Upvotes: 0

Hojo
Hojo

Reputation: 935

Could you try it after setting EnableViewState as false in that textbox?

Upvotes: 0

Related Questions