在哪里可以在asp.net上编写代码,我可以在任何网页上调用该代码. [英] Where to write a code in asp.net which I can call on my any webpage.

查看:60
本文介绍了在哪里可以在asp.net上编写代码,我可以在任何网页上调用该代码.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

< pre lang ="PHP"></pre>你好
我想知道vb.net中是否有类似于class的东西,只要引用其名称就可以在所有表​​单上调用.
同样,我该如何在asp.net中做到这一点.由于asp.net在类文件中的某些控件会显示错误,即对象引用未设置为对象的实例.
谢谢.

<pre lang="PHP"></pre>Hello
I want to know is there anything similar to class in vb.net which can be call on all the forms just by refering its name.
similarly how can i make it in asp.net. since, asp.net some controls in a class file it shows error i.e. object reference not set to an instance of an object.
Thanks.

推荐答案

创建一个类文件,然后在其中编写所有方法.在asp.net页面上创建该类的对象并使用该对象
Create A class file and write your all the methods there. and on asp.net page create object of that class and use that


我并没有真正理解问题,但是...

您可以简单地创建一个使其公开的类,并在该类中添加公共方法,然后从后面的aspx.cs代码访问该方法.
i don''t really get the question but...

you can simply create a class make it public and add public method in that class and access that method from your aspx.cs code behind.


Hello Mirzamujib,

请原谅我令人讨厌的代码,因为我正在快速地执行它,因此这是从aspx页面调用类成员的代码.

这是WebForm1.aspx
Hello Mirzamujib,

pardon me for the nasty code as i am doing it real quick so here''s the code to call class member from aspx page.

this is WebForm1.aspx
<html xmlns="http://www.w3.org/1999/xhtml">
<head  runat="server">
    <title></title>
</head>
<body>
    <form id="form1"  runat="server">
    <div>
        <%=new WebApplication1.Class1().MyName %>
    </div>
    </form>
</body>
</html>



这是另一堂课



this is another class

namespace WebApplication1
{
    public class Class1
    {
        public string MyName { get { return "naruto"; } }
    }
}




希望你有主意...对不起代码




hopefully you get the idea... sorry for the code


这篇关于在哪里可以在asp.net上编写代码,我可以在任何网页上调用该代码.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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