原来是用vb语法做的一个web自定义控件,今天用C#语法重写,其它所有的功能都没问题了,就是到了最后一步事件的问题上研究了整整一天,快要跳楼了.在vb语法中是用 raiseevent 引发事件,C#是通过委托,于是看了MSDN的关于事件委托方面的资料试了下就是不灵.部分代码如下:
public delegate void OnQuery(); public class test : WebControl
{
public event OnQuery qq = null;
ImageButton bt = new ImageButton(); public test(){
bt.id="aaa";
bt.ImageUrl = "1.gif";
bt.Click += new ImageClickEventHandler(ImageButton_Click);
this.Controls.Add(bt);
}
private void ImageButton_Click(Object sender, ImageClickEventArgs e)
{
if (qq != null) ////////////最郁闷的就是这里qq不管怎么折腾始终为null
{
qq();
}
protected override void RenderContents(HtmlTextWriter output)
{
....略...
}
} 根据MSDN时提供的例子程序一样的写法就是不灵,qq 始终为空.
顺便请教一下,原来在vs2003代码编辑器里选择左边下拉列表中的某一对象后自动在右边的列表中将列出其所有的事件,现在在vs 2008 里,只列出当前页面的那个类,右边的事件列表中也只自动列出page_load事件,不知是不是需要设置的还是啥问题呀?
谢谢
public delegate void OnQuery(); public class test : WebControl
{
public event OnQuery qq = null;
ImageButton bt = new ImageButton(); public test(){
bt.id="aaa";
bt.ImageUrl = "1.gif";
bt.Click += new ImageClickEventHandler(ImageButton_Click);
this.Controls.Add(bt);
}
private void ImageButton_Click(Object sender, ImageClickEventArgs e)
{
if (qq != null) ////////////最郁闷的就是这里qq不管怎么折腾始终为null
{
qq();
}
protected override void RenderContents(HtmlTextWriter output)
{
....略...
}
} 根据MSDN时提供的例子程序一样的写法就是不灵,qq 始终为空.
顺便请教一下,原来在vs2003代码编辑器里选择左边下拉列表中的某一对象后自动在右边的列表中将列出其所有的事件,现在在vs 2008 里,只列出当前页面的那个类,右边的事件列表中也只自动列出page_load事件,不知是不是需要设置的还是啥问题呀?
谢谢
public event OnQuery qq = null; 你这边是这样定义,又没有实例化对象当然是空的了
http://218.3.20.139/sql/
现在有个新问题,双击控件时代码编辑器里不会自动出现其事件声明代码,需要手工写,有点郁闷...