类调用函数 [英] class calling function

查看:131
本文介绍了类调用函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我有一个masterpage.master和default.aspx。我在类文件.cs中创建了一些函数我想在母版页中调用它我该怎么做?我是新来的?请帮帮我..



thnx提前

hi guys,

i have a masterpage.master and default.aspx. i was creating some function in class file .cs i want to call it in master page how can i do this? i am newe in this? pls help me out..

thnx in advance

推荐答案

母版页不能直接在子类中调用函数 - 它可能不存在!

它类似于从基类派生C#类的情况。基类不知道将从中派生哪些类,因此它不能调用其中的任何方法,除非它们是已经在基类中的方法的重写版本:它就像一个通用的Fruit试图在Grape上调用Orange Segment方法! :笑:

想要这样做的可能性是一个糟糕的设计选择的症状。





如果你必须的话,你可以做几件事。看看这里: http://stackoverflow.com/questions / 887178 / content-page-class-method-calling-from-master-page-class [ ^ ]
The master page can''t directly call functions in the child class - it may not exist!
It''s similar to the situation when you derive a C# class from a base class. The base class does not know what classes will be derived from it, so it can''t call any of the methods in it, unless they are overridden versions of the methods already within the base class: it''s like a generic Fruit trying to call a "Orange Segment" method on a Grape! :laugh:
The chances are that wanting to do this is a symptom of a bad design choice.


There are a couple of was you can do it though if you must. Have a look here: http://stackoverflow.com/questions/887178/content-page-class-method-calling-from-master-page-class[^]


这将进入您的MasterPage课程:

This goes into your MasterPage class:
if(Page is Default)
{
   Default def = (Default)Page;
   def.yourFunction();
}





祝你好运

Espen Harlinn



Best regards
Espen Harlinn


这篇关于类调用函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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