使用委托在父窗口窗体中引发子窗口窗体的事件 [英] raise event of child window form in parent window form using delegate

查看:70
本文介绍了使用委托在父窗口窗体中引发子窗口窗体的事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有文本框的子项和带有插入按钮的父表单。当我们点击父表单中的插入按钮时,子文本框中的数据必须插入到sqlserver数据库中。

I have one child with textboxes and parent form with insert button.when we click on insert button in parent form the data in textboxes of child has to inserted into sqlserver database.

推荐答案

这不是它的工作原理。特别是,了解在.NET中除了定义事件实例的类或结构之外的任何地方都不能调用事件是很重要的。即使在派生类中也不能这样做。在所有其他情况下,您不通过向某个事件实例的调用列表添加处理程序来调用事件,而是处理它们。你需要阅读关于.NET的事件,因为你现在似乎并没有真正的线索。不用担心,它会来的。



但是,在你的情况下,你不必使用活动。相反,您可以使用POST方法编写Web表单。它的提交按钮将使浏览器发送适当的HTTP请求,而不包括除HTML之外的任何代码(但在服务器端,您需要编写处理请求的代码,比如在数据库中存储数据)。请学习如何操作,例如,从这篇MSDN文章:

http ://msdn.microsoft.com/en-us/magazine/cc163736.aspx [ ^ ]。



-SA
This is not how it works. In particular, it''s important to understand that in .NET you cannot invoke an event from anywhere except the class or structure where the event instance is defined. You cannot do it even in a derived class. In all other cases, you don''t invoke events but handle them by adding a handler to the invocation list of some event instance. You need to read about events on .NET as right now you seemingly don''t really have a clue. Not to worry, it will come.

However, in your case you don''t have to use events. Instead, you can write a Web form with the "POST" method. Its submit button will cause the browser to send appropriate HTTP request without any code except HTML (but on server side, you will need to write the code processing the request and, say, storing data in your database). Please learn how to do it, for example, from this MSDN article:
http://msdn.microsoft.com/en-us/magazine/cc163736.aspx[^].

—SA


这篇关于使用委托在父窗口窗体中引发子窗口窗体的事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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