在asp.net(.ascx)中使用用户控件

编程入门 行业动态 更新时间:2024-10-14 16:22:51
本文介绍了在asp(.ascx)中使用用户控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我创建名为User.ascx的用户控件 它可以在本地和网络上的浏览器中很好地编译和运行. 但是当我在其他Web应用程序/网站中使用它时,它在下面给出了错误 对象引用未设置为对象的实例." 此错误发生在User.ascx控件中的asp:Label控件上 再见 如果可能的话,请给出解决方案!.......

I create User control with name User.ascx It compiles and run on browser very well in local and network also. But when i user it in other web application/web site it gives an error below "Object reference not set to an instance of an object." This error was on asp:Label control which is in User.ascx control Bye Give solution if possible!.......

推荐答案

我想您提供的信息不足以回答您的问题.此错误与用户自行控制无关.这是您没有实例化对象之一的编码错误.如果提供代码段,将更易于理解. 问候 Ahsan Sarfraz 如果信息有用,别忘了标记为已回答.谢谢 I guess the info you provided is not enough to answer your question. This error has nothing to do with the user contrl it self. it is a coding mistake where you havent instantiated one of the objects. If you provide the code snippet it would be more easier to understand. Regards Ahsan Sarfraz Dont forget to mark as answered if the info is usefull.thanks

您好, 1.您的用户控件应使用相对路径添加到页面.请确认您已将用户控件添加到网页的方式使用相对路径",而不是绝对路径". [NB:相对路径类似于".. \ Controls \ MyControl.ascx" 绝对路径类似于"file:///localhost/MyWeb/MyPage"或"C:\ Folder1 \ Folder2 \ MyPage.ascx"] 2.如果访问在用户控件内部定义(因此使用)的标签,则在网页中呈现时,它会为所有控件创建层次结构ID,因此您可能正在访问该标签.因此,您不会直接访问名称为"Label1"的标签.您必须在用户控件的FIndControl中进行操作才能获取UserControl的引用,然后再次在用户控件中需要调用FindControl方法来访问标签. 让我知道是否有帮助,或者请在引发异常的地方发布一些代码段. Hi, 1. Your user control should be added to page using relative path. Kindly verify that the way you have added the user control to web page uses "relative path" rather than "absolute path". [NB: A relative path is like "..\Controls\MyControl.ascx" An absolute path is like "file:///localhost/MyWeb/MyPage" or "C:\Folder1\Folder2\MyPage.ascx"] 2. If you access a label which is defined (hence used)inside the user control then at the time of rendering in web page, it creates hierarchical id for all conttrol, so as for the label you might be accessing. Hence you dont get that label directly accessing the name say "Label1". Either you have to do in FIndControl of user control to get the reference of UserControl then then inside the user control again you need to call FindControl method to access the label. Let me know if that helps or please post some code snippet where it throws exception.

更多推荐

在asp.net(.ascx)中使用用户控件

本文发布于:2023-11-25 00:27:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1627554.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:控件   用户   asp   net   ascx

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!