如何在Web用户控件(ASCX)中创建公共方法? [英] How to create a Public Method in a Web User Controll(ASCX)?
问题描述
我创建了一个带有6个Buttons.Which的用户控件,其中包括(NEW,Edit,Delete,SAVE,CLEAR,PRINT).默认情况下,编辑"和删除"按钮为禁用".我需要的是将此用户控件添加到页面时.在网格视图中选择一行时,需要启用该编辑和删除"按钮.有人可以告诉我如何声明一种从Web表单(.CS文件)启用该按钮的方法吗???多谢!!!!我想我将需要一种方法来完成该任务.如果有人可以在此问题上为我提供帮助,那将对我有很大帮助. div>
只需在事件中使btnUpdate.enable = true并将autopostback设置为true.
我建议改为在用户控件内设置公共属性
公共 布尔 ButtonEnabled { 设置 { btnSubmit.enabled = 值; } 获取 { 返回 btnSubmit.enabled; } }
这样,您可以从页面中的代码(如
usercontrol1.ButtonEnabled = false ;
甚至从页面的aspx标记为
< uc:usercontrol id =" 已启用按钮 =" false" xmlns:uc #unknown" / >
告诉我我的理解是否正确,我将尝试完善解决方案.
Hi , i create a User Control with 6 Buttons.Which includes (NEW ,Edit , Delete , SAVE , CLEAR ,PRINT). by default Edit and DELETE buttons are Disabled.What i need is when i add this user control to a page. need to enable that Edit and Delete button when select a row in the Grid view.can someone tell me how to declare a method to enable that buttons from a web form(.CS file)??? Thanks a Lot!!!! i guess i ''ll need a method for achieving that task.if someone could help me on this matter, that would be a great help for me.Thanks in advance!!!
just make btnUpdate.enable = true at the event and turn autopostback to true.
I suggest make public properties instead inside user control
public bool ButtonEnabled { set { btnSubmit.enabled = value; } get { return btnSubmit.enabled; } }
this way you can do it from code in the page like
usercontrol1.ButtonEnabled = false;
and even from the aspx markup of page as
<uc:usercontrol id="usercontrol1" buttonenabled="false" xmlns:uc="#unknown" />
Tell me if my understanding is not correct and i will try to refine the solution.
这篇关于如何在Web用户控件(ASCX)中创建公共方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!