从用户控件访问aspx中的按钮 [英] Accessing a button in aspx from a usercontrol

查看:84
本文介绍了从用户控件访问aspx中的按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在vew.aspx页面中有一个按钮.我想访问ControlModel.cs中的该按钮.但是他们彼此都不了解.如何访问控件类中的按钮.有人已经给出了解决方案,但是没有用.

并且该按钮在view.aspx.cs中可用.

我可以使用FindControl()方法在控件中找到按钮吗?我已经把5天放在这个没用的地方了,请帮忙.

如果您回答了问题后仍然有疑问,我该如何与您联系?

如果您没有收到我的问题,请进一步澄清.

There is a button in vew.aspx page. I want to access that button in my ControlModel.cs. but they both have no knowledge of each other . How can I access the button in my Control class. Some one gave a solution already but it didn''t work.

and the button is available in view.aspx.cs.

can i use the FindControl() method to find the button in my control.if so How do i use it. I put 5 days already on this nothing worked please help.

How do i get back to you if i still have questions after you answered my questio?.

please ask me for furthe clarification if you don''t get my question.

推荐答案

1)如果您想对按钮做出反应,请在用户控件中单击,然后使用页面的click事件将点击传播给用户控件.

2)如果要基于用户控件中发生的事情来设置按钮的状态,那么最好的选择是处理来自父控件可以使用的用户控件中的自定义事件,或者如果这是一个回发事件,公开一个或两个属性以在页面中获取相关信息并处理该级别的按钮.

用户控件绝不应尝试直接在父页面上进行修改.
1) If you want to react to the button click in the user control, then use the click event of the page to propogate the click to the user control.

2) If you want to set the state of the button based on something that happens in the user control, then your best bet would be to handle a custom event from the user control that can be consumed by the parent page, or if this is a postback event, expose a property or two to get information in the page that is relevant and deal with the button at that level.

At no time should the usercontrol be attempting to modify something on the parent page directly.


这篇关于从用户控件访问aspx中的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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