更新面板问题或可能的错误

发布于 2024-08-26 00:14:04 字数 621 浏览 3 评论 0原文

我在 UpdatePanel 中有 TextBox (多行)和 Label,我用 javascript __doPostBack(upEditReminder,id); 刷新它>

然后我将 LabelTextBox 文本设置为当前日期时间。

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

问题是 Label 已更新,但 TextBox 日期仅在页面加载时更新一次,但在 __doPostBack(upEditReminder,id); 时则不会更新触发。 我不知道问题出在哪里。

我也尝试过 textarea runat="server" 但仍然有同样的问题。

非常感谢您的帮助。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

缱倦旧时光 2024-09-02 00:14:04

这对我有用...与你所做的有什么不同吗?

aspx 代码片段:

<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>

代码隐藏片段:

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

单击“更新”链接会触发 UpdatePanel 的回发,该回发通过 ajax 刷新它,并且标签和文本区域都会获取更新的时间戳。

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.

所谓喜欢 2024-09-02 00:14:04

您可以在该文本框中将 EnableViewState 设置为 false 后尝试一下吗?

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

以歌曲疗慰 2024-09-02 00:14:04

您是否在代码后面的其他位置设置了文本框文本?我猜它在某个地方被覆盖了......

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

三生路 2024-09-02 00:14:04

在 UpdatePanel 内添加一个按钮。单击按钮,它是否同时更新标签和文本框?

此外,您进行的调用应该具有 updatepanel 的 ClientID,如下所示:

__doPostBack("ctrl00_ctrl01_upEditReminder",'');

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

夏尔 2024-09-02 00:14:04

从您的评论中,我注意到您正在尝试更新更新面板之外的文本框。这里的问题是您无法在 updatepanel 的回发中更新 updatepanel 之外的内容。这是使用更新面板的缺点之一。

如果您仍然想使用 updatepanel,我建议您在使用 javascript 和首选 jQuery 后更新其他页面的元素更新面板重新加载。您可以使用更新面板内的隐藏输入字段来传输数据。要在更新后刷新文本框,您可以使用以下 JavaScript/jQuery 代码:

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

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);
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文