I have just recently moved from VBscript / ASP classic to C# ASP.NET 3.5 and wanted to reuse a function which displays and image every time it's called using <%moregif%>
Sub MoreGif
response.write("
End Sub
How should I go about doing this?
Thanks
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
VulpesRank #55 · 29.2K reputationPosted Mar 10, 2011, 2:09 AM EST
If in Solution Explorer you right click on App_Code, select Add New Item, then select Class and at the bottom of the dialog give it a suitable name, say Utilities.cs, then press 'Add'.
You can then add your property like this:
public class Utilities
{
public Utilities()
{
//
// TODO: Add constructor logic here
//
}
public static string MoreGif
{
get { return @"
}
}
Now from any page you can do:
<%Response.Write(Utilities.MoreGif);%>
VulpesRank #55 · 29.2K reputationPosted Mar 10, 2011, 1:05 AM EST
Max Tenenbaum32 reputationPosted Mar 10, 2011, 1:18 AM EST
I encountered a protection level error with your script, which I fixed by adding public in front of void, but otherwise that worked great!
Now I need to reuse this function throughout the site, where I should I be storing and referencing the code from as using a web control doesn't seem the right way to go about it.
In addition I attempted to add this function to the master pages code behind page, but I get this error:
The name 'MoreGif' does not exist in the current context
Thanks
Max Tenenbaum32 reputationPosted Mar 10, 2011, 2:24 AM EST