从事件处理程序更改文本框的值对象在codebehind页 [英] Change textbox value from event handler for object in codebehind page

查看:83
本文介绍了从事件处理程序更改文本框的值对象在codebehind页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个对象,让我们称之为objK有接受字符串的事件消息。我有叫HandleObjKMessage(字符串s)页面背着我code事件处理程序。该方法看起来像目前这样:

I have an object, let's call it objK that has an event Message that accepts a string. I have a event handler in my code behind page called HandleObjKMessage(string s). that method looks like this currently :

void HandleObjKMessage(string s)
    {
        TextBox1.ReadOnly = false;
        TextBox1.Text += s+ Environment.NewLine;
        UpdateP.Update();

    }

objK是从正在运行一个反复的过程,我必须保持从用户更新的外部.DLL(组装)的对象。即使用事件的目的。

objK is an object from an external .dll(assembly) that is running an iterative process that I need to be keeping the user update from. That is the purpose of using an event.

我是找错了树?我是一个典型的WinForms家伙,这是令人沮丧的地狱了我。

Am i barking up the wrong tree? I'm typically a winforms guy and this is frustrating the hell out of me.

感谢。

推荐答案

我可能会误解你,但你必须要实例,然后添加一个事件处理该对象的事件的对象,当事件触发你想用户得到的更新后的数据

I might have misunderstood you, but you have an object that you instantiate, and then add an event handler to this object's event, and when the event fires you want the user to get the updated data?

如果是这种情况,这是不可能的。这完全是因为网络没有状态。有服务器和客户端之间没有永久连接。

If this is the case, it is not possible. This is simply because the web does not have state. There is no persistent connection between the server and the client.

当接收到你的页面的请求时,服务器将创建页面类的一个实例,并通过生命周期(初始化,加载等)运行一旦页面被渲染成HTML标记,服务器成事页面的实例,因此你的附加事件处理程序。

When a request is received for your page, the server will create an instance of your page class, and run through the life-cycle (init, load etc.) Once the page has been rendered into HTML markup, the server disposes the instance of the page, and thus your attached event handler.

您可以在的 MSDN

如果你真的想一路走下去,实际上推通知你的用户,你可以使用 SignalR ,但是这会增加相当一段复杂性。

If you really want to go all the way and actually push the notification to your user, you could use SignalR, but this adds quite some complexity.

这篇关于从事件处理程序更改文本框的值对象在codebehind页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆