简体   繁体   English

在ASP.Net aspx页面上使用的自定义控件中显示标签?

[英]Display label in custom control used on an ASP.Net aspx page?

I am using a Custom control in my aspx page. 我在aspx页面中使用了自定义控件。 This custom control has a error message label. 此自定义控件具有错误消息标签。 I need to display this label from the code behind on button click. 我需要通过单击按钮后的代码显示此标签。 How can i achieve this. 我怎样才能做到这一点。

Button and custom control is in Update panel. 按钮和自定义控件位于“更新”面板中。

I assume that in the custom control you have the label you want to show and the button you have on the update panel outside the custom control. 我假设在自定义控件中,您具有要显示的标签,并且在自定义控件外的更新面板上具有按钮。

If so, you should create a public method in your Custom control, something like public void ShowError(string message) and when you do the button click you call this method passing the text to display. 如果是这样,则应在“自定义”控件中创建一个公共方法,例如public void ShowError(string message) ,然后单击该按钮时,您将调用此方法以传递要显示的文本。 In the method implementation inside the custom control you will assign the message text to the label and display the label if not visible. 在自定义控件内部的方法实现中,您将消息文本分配给标签,并在不可见的情况下显示标签。 This should actually work either you use an update panel or not as long as both button and custom control are at the same time outside or inside the UpdatePanel but not one in and the other out. 只要您使用更新面板,或者只要按钮和自定义控件都同时位于UpdatePanel内部或外部,而不是一进一出,这实际上应该起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM