更新面板问题或可能的错误
我在 UpdatePanel
中有 TextBox
(多行)和 Label
,我用 javascript __doPostBack(upEditReminder,id); 刷新它>
然后我将 Label
和 TextBox
文本设置为当前日期时间。
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这对我有用...与你所做的有什么不同吗?
aspx 代码片段:
代码隐藏片段:
单击“更新”链接会触发 UpdatePanel 的回发,该回发通过 ajax 刷新它,并且标签和文本区域都会获取更新的时间戳。
This worked for me... is it different from what you're doing?
aspx code snippet:
codebehind snippet:
Clicking the "Update" link triggers the UpdatePanel's postback which refreshes it via ajax and both the label and textarea get the updated timestamp.
您可以在该文本框中将 EnableViewState 设置为 false 后尝试一下吗?
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...
在 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",'');
从您的评论中,我注意到您正在尝试更新更新面板之外的文本框。这里的问题是您无法在 updatepanel 的回发中更新 updatepanel 之外的内容。这是使用更新面板的缺点之一。
如果您仍然想使用 updatepanel,我建议您在使用 javascript 和首选 jQuery 后更新其他页面的元素更新面板重新加载。您可以使用更新面板内的隐藏输入字段来传输数据。要在更新后刷新文本框,您可以使用以下 JavaScript/jQuery 代码:
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: