在更新面板中执行代码时类似 Response.Write 的行为
有没有办法让 Response.Write 在 UpdatePanel 中工作,并且不会导致应用程序因明显原因而出错?或者,是否有一种方法无需使用超过一行 C# 代码即可获得类似的结果?
Is there a way to make Response.Write work in an UpdatePanel and not cause the app to error out for obvious reasons? Or, is there a way to get similar results without more than one line of code in C#?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以在更新面板中放置一个文字控件,并使用以下命令获得相同的效果:
You could just put a literal control inside your update panel and have the same effect using:
刚刚发现这可能对其他人有帮助。
您不能在更新面板内使用 Response.Write 或 Response.Redirect。
为了解决这个问题,你必须使用触发器。这用于从更新面板内部进行服务器访问
这里的 ControlID 是按钮或其他控件。例如,在按钮单击事件中,您可以在响应中写入一些文本。
Just found this could be helpful to other people.
you cannot use Response.Write or Response.Redirect inside update panel.
To solve this you have to use Trigger. This is used to make a server trip from inside an update panel
Here the ControlID is the button or other control. For example in the button click event you can write some text in the response.
获得类似行为(大致相似)的唯一方法是在更新面板中放置一个标签,该标签在该部分回发时进行更新,并将其值设置为某个值(这只需要一行代码来设置它)。 ..页面的其余部分根本没有更新,所以你无能为力。
为什么你想要这个功能呢?
The only way to get similar behavior (loosely similar) is to put a label within an update panel that is getting updated on that partial postback, and set its value to something (which would only take the one line of code to set it)... the rest of the page simply isn't getting updated, so there's nothing you can do.
Why do you want this functionality anyways?
Response.Write 不适用于 UpdatePanels,但正如 Spencer 提到的,您可以将信息放入文字中。
如果您正在调试,另一种选择是使用 System.Diagnostics.Debug.Assert() 函数。这样做的优点是
与任何事情一样,不要太过分,也不要把它们到处乱放,但我发现它是一个非常有用的调试工具。
Response.Write
does not work with UpdatePanels, but as Spencer mentioned, you can put your info in a literal.Another option is to use the
System.Diagnostics.Debug.Assert()
function, if you're debugging. The advantages to this areAs with anything, don't go overboard and put them everywhere, but I've found it to be a very useful debugging tool.
我使用的解决这个问题的一个简单方法是调用 JQuery 函数 html() 并调用 Response.Write()...例如,假设我想更新 UpdatePanel 中的一些 html 文本,我会这样做:
使用 Response.Write (),那就简单了:
Response.Write("[TextToBeAddedToHTML]");
但使用 Jquery 有点复杂,你必须将 Jquery 库包含到 Html 页面中:
A simple solution to this problem I use is to call JQuery function html() insted calling Response.Write()... For example, lets say I wanna update some html text inside UpdatePanel I would do something like this:
With Response.Write(), it would be simple as this:
Response.Write("[TextToBeAddedToHTML]");
But with Jquery its little complicated, and you have to include Jquery library to Html page: