在运行时设置ModalPopupextender的TargetControl [英] Set TargetControl of ModalPopupextender at runtime

查看:92
本文介绍了在运行时设置ModalPopupextender的TargetControl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在aspx页面后面的代码中创建了一个按钮控件.我想将此按钮控件设置为ModalPopupExtender的TargetControlID.
这是我正在编码的内容:

I have created a button control in code behind of an aspx page. I want to set this button control as TargetControlID of a ModalPopupExtender.
Here is what I am coding:

Button btnPostComment = new Button();
 btnPostComment.Text = "Post Your Comment Here";
 btnPostComment.ID = "btnPostComment";
 ModalPopupExtender1.TargetControlID = Convert.ToString(Page.FindControl(Convert.ToString(btnPostComment.ClientID)));



它给出了一个例外:
"ModalPopupExtender1"的TargetControlID无效.该值不能为null或为空.



It gives an exception:
The TargetControlID of ''ModalPopupExtender1'' is not valid. The value cannot be null or empty.

How can I set the targetControlID at codebehind?

推荐答案

尝试:
ModalPopupExtender1.TargetControlID = "btnPostComment";


好,这是您的问题.看起来在设计时您没有将任何控件分配为TargetControlID.因此,您将获得一个例外.默认情况下,您需要提供的默认内容是任何内容,以便代码执行正常,稍后在运行时,您可以根据需要更改targetControl.

试试这个:
将页面中的隐藏按钮设置为targetcontrolID. (而设计时间本身)
我的意思是隐藏按钮,放置一个按钮并将其样式设置为display:none
现在,在运行时将targetControlID更改为"btnPostComment"

应该可以!
Ok, here is your issue. Looks like in designtime you have not assigned any control as TargetControlID. Thus you get an exception. What you need is provide anything by default from before such that execution of code works well and later at runtime you can change the targetControl as you want.

Try this:
Set a hidden button in the page as the targetcontrolID. (while design time itself)
By hidden button i mean, place a button and set it''s style as display:none
Now, at runtime change the targetControlID to "btnPostComment"

That should work!


这篇关于在运行时设置ModalPopupextender的TargetControl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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