Using App_Code shared code in page code-behind AND code-front

Hi all,

I've only just come across what seems to be the 'correct' way of making use of shared code in my .Net sites: I code some classes in a .cs (in my case - i'm using c#) file. I then put them inside namespaces. To make use of the classes in the code-behind of my web pages, I simply add a "using MyNamespace;" line at the top, and then I can make use of a class' contents like so: "MyClass1.MyString1(SomeVariablesToSend)".

Now that works fine when working in the codebehind, but what happens when I want to call the class/string from my code-front file? E.g. I have a repeater on the code front. The code behind runs a query and sends an ID and a Name field to the repeater. The repeater just shows the Name field, but wants to send the ID field value into "MyClass1.MyString1(SomeVariablesToSend)", knowing that the class will return some other value/text that will then be written onto the page instead of just the meaningless ID of that record. The problem is that when I attempt to call the class/string like I do in the codebehind e.g. MyClass1.MyString1(Eval("ID")), I simply get a "MyClass1 does not exist in the current context" error. Clearly the code-front doesn't have access to the class... Can anyone tell me how to make my class available to the code-front? The only other solution I can think of is to have the class that's in the codefront to be a new one that's called from the codebehind. That, in turn, can then call "MyClass1.MyString1(SomeVariablesToSend)" from the App_Code folder.

Any help very much apprecaited!

Ramic Solutions
5/31/2008 11:26:16 AM 91979 articles. 4 followers. Follow

1 Replies

Similar Articles

[PageSpeed] 56

you use the full namespace when making a method call


Mike Banavige

Need a site code sample in a different language? Try converting it with:
5/31/2008 2:16:33 PM

Similar Artilces:

Setting width for .net controls in code(.aspx) page using function call in code behind..
Hi,  Currently I am trying to set the width of the Table as follows. <asp:Table width="<%=GetWidth()%>" >   and code behind protected Unit GetWidth() { return Unit.Percentage(50); }     It's not working. I know that it works if I set the width complete on some page event(like page_load) of code behind....   Is there a way to maintain the same syntax like calling code behind function in design page...i.e. calling function of .aspx.cs in .aspx page and assign the width as shown above.   Thanks and regards, Giridhar...

Get html code of aspx page from code behind
Hi all, Do you how we can do what I mention in the title?Example: aspx code <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Header.aspx.cs" Inherits="Header" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""> <!--js--> <script type='text/javascript'> alert('hello'); </script> <!--/js-->  Is there any way that in the code behind I can have the above string?. Actually I like to ge...

Looping through datareader from code-behind in code-front page
Hi all - complete newbie here :-) I'm just getting familiar with codebehind and all that it entails. I'm also a newbie to webstandards-design, so i'm trying to keep all of my code away from traditional html tags like <table> etc. and instead use <div>'s and <span>'s for pretty much everything. Problem i've found is that most of the ASP.Net web controls (e.g. DataGrid) seem to create traditional tags (<table> in the case of a DataGrid). On a website I did previously, I found that I could manually loop through the results of a DataReader just like you have to in classi...

Code Behind or not Code Behind
Ok i am confuse now.... A lot of books are showing pages without code behind (the code is integrated in the .aspx) Is it better to use the code behind or not. Is there any difference between using VB.NET or C#.NET except for the code synthax. Thank you and come again. A lot of samples show inline code just for simplicity.. i personally use code-behind because I like to seperate my code from presentation. As for VB.NET or C#, its your preference.. there is no difference really when its all said and done. From a purely mathematical sense, having everything in a single file would s...

Using code compiled code behind instead of aspx pages
Hi There, I have some code I wish to release to a customer (its a photo gallery with upload, autothumbnail and watermarking facilities). Currently this is in one stonking vb aspx file, and I was working under the (wrong) assumtpion I could just obfuscate the code ala html mangler (which I find I cant). So, I need to create a .vb code behind - which is ok - I dont mind the extra work, but having read some bits about this I have the following questions and would be grateful if anyone could point me in the right direction. 1) I dont particularly want the user screens html source vie...

what about the code-behind (code behind)
One MAJOR difference between AJAX.NET and Atlas.NET seems to be that AJAX.NET is able to expose methods in your codebehind to the client. Why doesn't Atlas do this? Or am I mistaken? With AJAX.NET it's just a simple line or two:  Ajax.Utility.RegisterTypeForAjax(GetType(myClass)) <Ajax.AjaxMethod()>Public Function myFunction PLEASE tell me Atlas has something comparable to this. I don't have the time to rewrite all my code-behind methods in javascript or atlas script. All you need to do in Atlas to expose a method on your page (or its code behind class) is to put a [WebMet...

To code or not to code?
The rise of Open Source software adoption has brought with it increased awareness of non-proprietary programming technologies.,to-code-or-not-to-code.aspx -- "Never drive faster than your ANGEL can fly" ...

Creating, Populating, Sorting, Paging and Gridview with Code Behind (Code Behind ONLY!!!) using an ArrayList as a data source
I need someone to point in the right direction or a sample code to achieve the following Creating, Populating, Sorting, Paging and etc..everything...with Gridview using Code Behind (Code Behind ONLY!!!) and using an ArrayList as a data source I DONT WANT TO ADD ANYTHING IN THE DESIGN MODE LIKE BELOW. EVERYTHING SHOULD BE DONE IN CODE BEHIND. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "

Sorting, Paging in Gridview with Code Behind (Code Behind ONLY!!!)
Does anyone know of a definitive tutorial of VB code-behind for paging and sorting parameters for GridViews?  I've been all over this site and I know more than I need to know about the SortExpression parameter, the ASP.NET tutorials on Paging and Sorting, and the many postings on these forums for same.  Please don't take the copout approach and give me links for what I've already read.  I'm specifically looking for something that gives a detailed explanation for such things as the PageIndexChanging, PageIndexChanged, SelectedIndexChanging, SelectedIndexChanged,...

Inline Coding (i.e. no Code-behind) and Wilson Pages (.Net 1.1)
Hi, I'm developing a personal web site and planning on hosting it on Brinkster, but Brinkster does not allow codebehind or using Dlls (from what I understand). But I would still like to use Wilson Master Pages, if possible.  I downloaded the free source code from the Wilson Master Pages website, but I'm not an advanced enough .Net programmer to firgure out how to use the source code using inline code.  Normally, you would use something like:<%@ Register TagPrefix="Wilson" Assembly="WilsonMasterPages" Namespace="Wilson.MasterPages" %>  on your templated pages...

Page Code VS Code Behind
Is there a way to turn-off code behind for and write script on .aspx altogether? Regards: Waqas Mahmood Khan PakistaneMale ;) It's up to you. Simply don't use code behind if you don't want it. VS.NET will automatically create code behind files for you. It is a better way to organise your code, although the downside is that you must rebuild more often. Keith PattonTechnical Director Ethical Media You can use Asp.Net Web Matrix Right now , Visual Studio standard is to use code-behind. I've gotten used to it, and it does help seperat...

Seperating Admin code in code-behind from general code
Hi guys, I just want to know if it would improve the functioning of my site to create two seperate dlls: One of the dll's would contain all the code for the general functioning of the site, and the other dll would contain all of the code for the administration elements of the site. Thanks GP...

Code-Behind versus Code-Inside and Code-Beside
Can someone explain to me how the code gets compiled when you do code-inside (like in webmatrix) as oposed to code-behind? WHen you do the code-behind I know all the code gets compiled at compile-time into a dll assembly. And I think that code-inside gets compiled at run-time. But what if you have a mixture of the two and you have a dll assembly with code-beside modules, how do they get compiled into the assembly? Maybe I'm wrong or confused, can someone clarify? I'm also aware of the Visual Studio 2005 code-beside also, will that change anything? thanks, Frank For a general...

reusable code
 I have a page of code that instead of putting it in each pags code behind, I would like to be able to jsut include it in the code behind of each page so that it gets executed each time. This way I could jsut edit the one file and th changes woudl be site wide in thepages that have this as an include in the code behind file.What is the bet way to do that? Any examples?Thanks Hi, You could create a base class for the code-behind classes (put every code-behind class to derive from this common base class), when changes to the base class would apply to the derived classes.Thanks,Teemu Ke...

Web resources about - Using App_Code shared code in page code-behind AND code-front -

Looking at the code behind our three uses of Apache Hadoop - Facebook
Facebook Engineering hat eine Notiz mit dem Titel Looking at the code behind our three uses of Apache Hadoop geschrieben. Du kannst den vollständigen ...

How Heartbleed Works: The Code Behind the Internet's Security Nightmare
By now you've surely heard of Heartbleed, the hole in the internet's security that exposed countless encrypted transactions to any attacker who ...

Anatomy of an interactive: a look at the code behind our Second Screen
... and Paralympics coming to town, this presented the perfect opportunity to try it on. Being mainly responsible for the client-side code, I'll ...

How Heartbleed Works: The Code Behind the Internet's Security Nightmare
By now you've surely heard of Heartbleed, the hole in the internet's security that exposed countless encrypted transactions to any attacker who ...

Resources last updated: 1/5/2016 3:24:33 PM