如何在用户控件中投射页面 [英] How do I cast a page in a usercontrol

查看:67
本文介绍了如何在用户控件中投射页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在ViewComplaint.aspx页面中有一个按钮"TrnsButton".现在,我想从用户控件中访问caseStageTransition.ascx.cs的按钮.因此,我在用户控件类中执行了以下代码.将页面强制转换为Viewcomplaint,然后就可以获取fincontrol智能.现在我正在尝试通过findcontrol中的按钮.我得到的错误是

I have a button " TrnsButton" in ViewComplaint.aspx page. Now i wanna access the button from my usercontrol which is caseStageTransition.ascx.cs. so I did the below code in the user control class.Im casting the page to Viewcomplaint then i was able to get the fincontrol intelisence. and now I''m trying to pass the button in findcontrol. the error i''m getting is

Button v = ((ViewComplaint)Page).FindControl("TrnsButton");




1)错误非静态字段,方法或属性``System.Web.UI.Control.Page.get''需要对象引用
2)错误无法将类型"System.Web.UI.Control"隐式转换为"System.Web.UI.WebControls.Button".存在显式转换(是否缺少转换?)




1) ErrorAn object reference is required for the nonstatic field, method, or property ''System.Web.UI.Control.Page.get''

2) Error Cannot implicitly convert type ''System.Web.UI.Control'' to ''System.Web.UI.WebControls.Button''. An explicit conversion exists (are you missing a cast?)

推荐答案

对于错误2,您需要转换为Button
For error 2 you will need to cast to Button
Button v = (Button)((ViewComplaint)Page).FindControl("TrnsButton");


这篇关于如何在用户控件中投射页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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