跨回发的c#委托
当我在会话状态中存储委托(指向页面方法)时,在回发后检索它并执行它,委托的目标是旧页面对象而不是当前页面对象,无论如何都可以更改页面对象的目标委托以便它在当前页面对象上执行该方法?
我曾考虑过使用静态页面方法,但后来我无法访问页面上的控件,这违背了我想要做的目标,即更新文本框。
When i store a delegate (that points to a page method) in session state, retrive it after a postback and execute it the target of the delegate is the old page object and not the current one, is there anyway to change the target of the delegate so that it executes the method on the current page object ?
I have thought about using a static page method but then i don't have access to the controls on the page which defeats the object of what i am trying to do, which is update a text box.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我对此有点紧张。 Jon Skeet 和 Mehrdad 的建议都有效(当然),但页面实例应该在请求完成后被处理。 该委托可能会阻止这种情况的发生,从而导致 .Net 相当于内存泄漏。
也许您可以使用反射并将 System.Reflection.MethodBase 或 System.Reflection.MethodInfo 对象放入会话中以便稍后调用。
I'm a little nervous about this. Both Jon Skeet's and Mehrdad's suggestions will work (of course), but page instances are supposed to be disposed after a request completes. This delegate could be preventing that from happening, leading to the .Net equivalent of a memory leak.
Perhaps you could use reflection and put a
System.Reflection.MethodBase
orSystem.Reflection.MethodInfo
object in the session to invoke later instead.让您的委托将新页面作为其第一个参数,并在调用它时传递
this
。Make your delegate take the new page as its first parameter, and when you call it pass
this
.