开发者

updatepanel problem or possible bug

开发者 https://www.devze.com 2022-12-23 05:33 出处:网络
I have TextBox (multiline) and Label in an UpdatePanel which I refresh with javascript __doPostBack(upEditReminder,id);

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 t开发者_如何学Pythono 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.


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.


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


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


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


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

精彩评论

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

关注公众号