您的位置:程序门 -> .net技术 -> c#



一个疑难问题,至今找不出原因在哪里,希望大家帮忙!


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


一个疑难问题,至今找不出原因在哪里,希望大家帮忙![已结贴,结贴人:babywywy]
发表于:2007-07-26 17:05:01 楼主
我用的是.net2003;
我用个repeater列出新闻的标题的列表
<itemtemplate>
<asp:hyperlink   cssclass= "webnews "   target= "_blank "   id= "hnews "   runat= "server "> </asp:hyperlink>
</itemtemplate>
然后在后台hnews.navigateurl   =   string.format( "newsdetail.aspx?newsid={0} ",   id);
在newsdetail.aspx里我放了个名为commentpart的用户控件用来发表评论,然后给它赋参数:
commentpart   cp   =   new   commentpart();
cp   =   (commentpart)this.findcontrol( "commentpart1 ");
cp.newsid   =   this.newsid;
问题来了,第一次打开任何一个新闻详细界面的时候,都能正常显示,但是第二次打开新闻详细界面的时候会在cp.newsid   =   this.newsid;这句提示未将对象引用到实例。我试着排出有可能引发问题各种原因都失败了,请大家帮我找找是哪里的问题,谢谢!
发表于:2007-07-26 17:11:001楼 得分:10
请检查cp是不是被你dispose了??

一般运行后被释放的对象会造成只能运行一次。

==================================================================
博客空间:http://blog.csdn.net/lovingkiss
资源下载:http://download.csdn.net/user/lovingkiss
email:loving-kiss@163.com
优惠接单开发,收费带初学者,组件控件定制开发,成品源代码批发
联系方式:q64180940(请清楚注明业务还是技术咨询)     全天在线
==================================================================
发表于:2007-07-26 17:11:112楼 得分:0
this.newsid这个值是空的吧
发表于:2007-07-26 17:11:553楼 得分:10
编程需要学会中断,看看是那一个变量引发的故障;

==================================================================
博客空间:http://blog.csdn.net/lovingkiss
资源下载:http://download.csdn.net/user/lovingkiss
email:loving-kiss@163.com
优惠接单开发,收费带初学者,组件控件定制开发,成品源代码批发
联系方式:q64180940(请清楚注明业务还是技术咨询)     全天在线
==================================================================
发表于:2007-07-26 17:16:554楼 得分:0
关注之中,帮你顶一下
发表于:2007-07-26 17:20:595楼 得分:10
cp   =   (commentpart)this.findcontrol( "commentpart1 ");
这句执行后看看cp是否为null
另外就是this.newsid是什么
发表于:2007-07-26 17:23:586楼 得分:0
但是第二次打开新闻详细界面的时候

=======

这里怎么理解?   过5分钟之后回来从浏览器输入地址打开?

还是点击按钮,提交页面?
发表于:2007-07-26 17:24:577楼 得分:0
commentpart   cp   =   new   commentpart();
cp   =   (commentpart)this.findcontrol( "commentpart1 ");
cp.newsid   =   this.newsid;

==========

lz   在哪里将   cp   加入到页面的控件集合中?
发表于:2007-07-26 17:26:288楼 得分:10
对了,用户控件是不能用   new   来动态加载滴,



commentpart   cp   =   page.loadcontrol( "commentpart.ascx所在虚拟路径 ")   as   commentpart;
发表于:2007-07-26 17:29:479楼 得分:0
看见的帮忙

http://community.csdn.net/expert/topic/5677/5677248.xml?temp=.4019739

谢谢
发表于:2007-07-26 17:42:1110楼 得分:0
不好意思,我忘了说明,我检测了this.newsid是有值得,就是cp.newsid这里有问题,我刚才检测了,在第二次打开新闻界面的时候cp的确是空的,刚才lovingkiss说的是不是被我dispose了,我没找到我在哪里dispose了,能不能说的再说的详细些?谢谢
发表于:2007-07-26 17:46:4311楼 得分:0
不用过5分钟,用_blank或者_self连续的打开新闻连接都会出现问题,我是这样加载控件的:
private   void   page_load(object   sender,   system.eventargs   e)
{
this.newsid=tool.cint   (this.getquerystring   ( "newsid "));
if(!ispostback)
{
this.shownews   ();
commentpart   cp   =   new   commentpart();
cp   =   (commentpart)this.findcontrol( "commentpart1 ");
object   o1   =   cp;
cp.newsid   =   this.newsid;
}
}
发表于:2007-07-26 17:54:4312楼 得分:10
1。
usercontrol   就没有实现   idisposable   接口,不会有   dispose   方法

2。
我是这样加载控件的:

commentpart   cp   =   new   commentpart();
cp   =   (commentpart)this.findcontrol( "commentpart1 ");
=======

哪里加载的?commentpart1   拽到   .aspx   的?

另外,这里   new   一个,纯属浪费  

commentpart   cp   =   null;
cp   =   (commentpart)this.findcontrol( "commentpart1 ");
发表于:2007-07-26 17:55:3913楼 得分:10
代码贴全点,不要忽略重点,一堆无用信息
发表于:2007-07-26 18:18:3514楼 得分:0
不好意思我还是不大会贴代码,commentpart是拖拽到newsdetail.aspx里的,所以我刚才贴的代码是在newsdetail.aspx里加载的,我刚才用了commentpart   cp   =   null;
cp   =   (commentpart)this.findcontrol( "commentpart1 ");,第二次连接到newsdetail.aspx的时候cp还是未定义的值
发表于:2007-07-26 19:05:4515楼 得分:0
jf
发表于:2007-07-26 19:15:4716楼 得分:0
up
发表于:2007-07-26 19:19:4017楼 得分:10
把newsdetail里面的有的控件遍厲出來,看看commentpart1對像是否還存在。
发表于:2007-07-26 22:43:3318楼 得分:0
回楼上的,先问一句,如果不存在呢?我确实已经将空间拖到newsdetail里了,怎么可能会不存在呢?
发表于:2007-07-27 08:07:1419楼 得分:10
if(!ispostback)    
{
this.shownews   ();
commentpart   cp   =   new   commentpart();
cp   =   (commentpart)this.findcontrol( "commentpart1 ");
object   o1   =   cp;
cp.newsid   =   this.newsid;
}
当用户发表评论后,此段代码不会执行的哦,cp当然不会被加载的.
你这样动态的加载.cp的状态是不会被保存的哦.
所以这段代码应该放在!page.ispostback   的外面吧.
发表于:2007-07-27 08:17:0120楼 得分:0
帮顶
发表于:2007-07-27 08:19:4121楼 得分:0
mark!
发表于:2007-07-27 08:22:2922楼 得分:0
up
发表于:2007-07-27 08:39:3423楼 得分:10
if(!ispostback)    
{
this.shownews   ();
commentpart   cp   =   new   commentpart();
cp   =   (commentpart)this.findcontrol( "commentpart1 ");
object   o1   =   cp;
cp.newsid   =   this.newsid;
}

这里只在页面第一次加栽时执行
发表于:2007-07-27 08:39:5724楼 得分:0
commentpart   cp   =   new   commentpart();
cp   =   (commentpart)this.findcontrol( "commentpart1 ");
cp.newsid   =   this.newsid;
---------------------------------
bs   的特点:无状态
--------------------
你的创建控件代码放在   load事件,加入判断ispostpage?

发表于:2007-07-27 08:40:4525楼 得分:10
可能你需要用一下viewstate来保存一下你的值
发表于:2007-07-27 10:21:1826楼 得分:0
回楼上的,用viewstate保存自定义的变量类型需要实现iserialization接口,使变量可被序列化   ,比较麻烦,我用session保存似乎可以,我再多调试下!
发表于:2007-07-27 11:16:5227楼 得分:0
问题解决,开始给分


快速检索

最新资讯
热门点击