views:

260

answers:

5

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.

A: 

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

Hojo
I tried didn't work
Woland
A: 

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

Paddy
now its the only place where it is modified
Woland
+2  A: 

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.

Rudism
the code is pretty much the same but it is in usercontrol with is placed on the master page
Woland
A: 

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",'');

Raj Kaimal
A: 

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);
});
Prutswonder