C# - To Use Static Functions If No Class Members Are Needed?

Jan 21, 2011

I have a member function that does not depend on any member variables of the class. (in my case the class is an ASP.Net Page)

The function is protected, I dont need it outside of this class. Its only purpose is to build an URL from an given object.

Should I make all my functions static if they dont depend on the class, even if they are not used outside of this class?

View 6 Replies


Similar Messages:

C# - What Are The Limits Of Static Members Using

Mar 7, 2011

I ask if i can use static variables in my web application, what are the alternatives to (static)? when i use static variable in specific page and more than one user use the application , it make conflict data(incorrect data).what are the limits of static members using?are static members are shared in memory?

View 3 Replies

Access Global.asax Static Members?

Dec 30, 2010

If we declare a static variable in Global.asax then how to access it inside an ASP.NET page ?

<script runat=server">
public static object myObject = new MyClass();
// Application_Start() and other stuff goes here.
</script>

And, is this a good idea for storing a global object (same instance for all requests) ?

View 3 Replies

C# - How To Access A Private Data Members Of Base Class In The Derived Class

Aug 20, 2010

Since we can access the private data member of base class in the derived class with the help of friend function. How can we do the same in C# asp.net? I mean whats the alternative of friend function in C# asp.net

View 2 Replies

Calling Other Functions From A Shared (or Static) Function

Aug 20, 2010

I get this error: Cannot refer to an instance member of a class from within a shared method or shared member initializer without an explicit instance of the class.

Partial Class _Default
Inherits System.Web.UI.Page
<WebMethod()> _
Public Shared Function ParseData() As String
Dim value as string = GetValue()
End Function
Private Function GetValue() as String
Return "halp"
End Function
End Class

I know it has something to do with the fact that the first function is shared and the second function should probably be Public as well but I don't fully understand the reason behind it. Probably not relevant but I'm calling the web method from some javascript.

View 1 Replies

Vb.net - Architecture Specific To Shared/Static Functions?

Apr 30, 2010

If for example you have a function Public shared function GetStockByID(StockID as Guid) as Stock Is that function common to all current users of your application? Or is the shared function only specific to the current user and shared in the context of ONLY that current user? So more specifically my question is this, besides database concurrency issues such as table locking do I need to concern myself with threading issues in shared functions in an ASP.Net application?In my head; let's say my application namespace is MyTestApplicationNamespace. Everytime a new user connects to my site a new instance of the MyTestApplicationNamespace is created and therefore all shared functions are common to that instance and user but NOT common across multiple users. Is this correct?

View 2 Replies

C# - How To Lock A Private Static Field Of A Class In One Static Method

Mar 26, 2011

I have a private static field in my Controller class in an MVC web application.

I have a static method in that controller that assigns some value to that static field, I want to apply lock on that static field until some other instance method in the controller uses the value stored in the static field and then releases it.

DETAILS:

I have a controller named BaseController having a static ClientId field as follows and two methods as follows:-

public static string ClientId = "";
static void OnClientConnected(string clientId, ref Dictionary<string, object> list)
{
list.Add("a", "b");
// I want the ClientId to be locked here, so that it can not be accessed by other requests coming to the server and wait for ClientId to be released:-
BaseController.clientId = clientId;
}
public ActionResult Handler()
{
if (something)
{
// use the static ClientId here
}
// Release the ClientId here, so it can now be used by other web requests coming to the server.
return View();
}

View 1 Replies

Public Static Variable Declared In Public Static Class MyGlobals In A 'Code File' Template?

Jan 27, 2011

I have a question about C Sharp ASP.NET:Is there a difference (in code speed, resources) between:public static variable declared in public static class MyGlobals in a 'Code File' template;and the variable declared in a normal 'Class File' template;I use this variable in 2 different Class Files and also in _Default Page codebehind cs file.In fact in my case I need about 20 global variables of type List<string>.

View 9 Replies

Create A Class To Keep Variable And Functions?

Feb 2, 2011

I have several Include files in asp classic that I would like to convert to the class in C#, I have bunch of variable, Constraint, functions, DB connection. Is class the best way to convert them?

View 2 Replies

Creating Objects From C# Class To Use Them In Database Functions?

Nov 25, 2010

I have created class in C# i need to use objects from this class to add them to a databse table.

the information come from textbox go into the object of the class than from this object i want to preform databse function.

View 2 Replies

Security :: Filtering Members List / Only Members Whose Name Contains The Typed Characters Will Show Up In The Gridview?

Apr 28, 2010

Our site has a page for maintenance of existing members (e.g. adding / changing roles, etc.)This page currently uses a gridview to show a complete list of all members, based on GetMembers() method to populate it.However, as the number of users has grown to several hundred, it has become difficult to locate a particular user by paging through several pages.Is there a way to narrow down this list, maybe with a filtering textbox, so that as you start typing into that textbox, only members whose name contains the typed characters will show up in the gridview?

View 8 Replies

Web Forms :: Access Base Class Functions From Master Page?

May 14, 2010

I have a base class called BasePage, and a master page called SiteMaster. All my content pages inherit BasePage using BasePage instead of System.Web.UI.Page. Now, I need to access some functions in BasePage from my master page SiteMaster, let's say, the function is called "DisplayClientName()". How can I do it? Searched the Web, have found tons of similar questions but not solid solutions.

View 2 Replies

DataSource Controls :: SQLDataAdapter Postback / Create A Class, DataCommon, To Contain All SQL Data Manipulation Functions?

Apr 22, 2010

I'm trying to create a class, DataCommon, to contain all my SQL Data manipulation functions. I've created a Subroutine called Init that initializes a SQLDataAdapter:

[Code]....

From my other classes I am creating an instance of DataCommon, calling Init, and calling another subroutine in DataCommon that pulls data from SQL and loads the data into my dataset. This part is working great -- no problems at all. I'm loading three different Datatables in the Dataset with no issues.

At this point, I'll perform my various manipulations on the datatables -- add/delete/modify rows -- again with no problems. All of this is creating postbacks...and this is where my problem begins. After I've done all my manipulations to the data and am ready to update my SQL tables, I have to re-initialize my SQLDataAdapter. I thought I could do something like:
[Code]....

But I get the error: Exception inserting Class. Thread was being aborted.

In my initial data load from SQL, each datatable is getting loaded from a single SQL table, so I was hoping to use the autogenerated Update/Insert/Delete statements by the SQLDataAdapter. As a test, as soon as I filled the dataset initially, I added a new row to one of the datatables and used the SQLDataAdapter.Update() method before a postback occurred, and it worked perfectly.

So, with all that being said, I guess my question is, how do I reconnect the table mappings between my SQLDataAdapter and dataset to autogenerate the updates after a postback occurs? I've tried researching this, but I get confused after reading about FillSchema vs TableMappings vs everything else I've read about.

View 2 Replies

How To Access A Module Or A Public Class With Public Shared Members From Inline Vb Code

Feb 10, 2011

I can access a module from code behind but not from the aspx page in inline VB code <% ... %>.

I know its got to be something simple but I can't seem to find the answer anywhere.

View 1 Replies

Static Class In App_Code?

Jan 8, 2010

If a static class is put in App_Code, does that imply only one instance will be created, shared by different http requests?Or each request still brings one request?

View 3 Replies

Use A Static DbUtil Class For Web Is It Dangerous?

Oct 4, 2010

is it ok to use something like this in the web:
(my application is on asp.net mvc)

public static class DbUtil
{
public static int Insert(object o, string cs)
{
using (var conn = new SqlConnection(cs))
using (var cmd = conn.CreateCommand())
{
conn.Open();
return Convert.ToInt32(cmd.ExecuteScalar());

[Code]....

View 2 Replies

MVC :: Accessing An Existing Static Class?

Mar 15, 2011

So i have some existing functionality from an older ASP.Net app that is a static class.

Say there's a static method in that class that returns a dataset that I would like to bind to something like a gridview or whatever I can build using MVC3.

View 2 Replies

C# - Access Static Class From Form?

May 10, 2010

I am using <%# MyFormatClass(Eval("fieldname")) %> to display data in a grid view on my page. MyFormatClass works fine, but now I want to move it to a central location that can be used by many pages. When I try to access the class <%# Utils.MyFormatClass(Eval("fieldname")) %> it no longer works. Is this something we are allowed to do?

View 1 Replies

Database - Storing Connection In A Static Class?

Mar 4, 2010

Since I'm using Postgresql and can't use LINQ to SQL, I wrote my own wrapper classes.

This is a part of the Student class:

[code]....

It works now! I replaces all Run methods in the Student class with DB.Run

But I want to know if it will work fine with a lot of people online, not me only. I'm not sure how static things work with ASP.NET, maybe it'll eat a lot of memory?..

View 3 Replies

Way To Generate Links Automatically Via A Static Class

Jun 10, 2010

I would like to generate my links automatically via a static class in each of my aspx pages (or in a common BasePage).Currently I use this:

private const string TEMPLATE =
"~/One.aspx";
public static string Link ()
(
string link = String.Format(TEMPLATE);
return link;
)

But the name of my page, One.aspx is hardcoded. Is it possible to generate the path instead of this hardcoded constant TEMPLATE. You should know that I do not instantiate the class before creating the link.

View 1 Replies

C# - How To Create A Static Array Containing Custom Class

Jan 6, 2010

I have a method that returns an array of custom class objects that are created by parsing a text file. At the moment every time I use it I am rereading the file which isn't very efficient.

What I wat to do is create an array containing the objects when the page loads and store them in an array which can then be used later.

[Code]....

I thought I could create the static object using something like:

static Album myAlbums[] = readArray("Albums.txt");

but I am getting the following error:

A field initializer cannot reference the nonstatic field, method, or property 'B2M._Default.readArray(string)'

I am new to C# so this is probably something dumb. (Feel free to poke fun in my general direction if this is the case!)

View 2 Replies

C# - How To Access Singleton Class's Static Method

Nov 17, 2010

I have some confusion with singleton class, below are my some points:

1.Can singleton class have static method?,if yes then how we call that methods?
2.what is main difference between Static class and Singleton Class?

I have created my singleton class as follows:

[Code]....

In Above class structure I have created two method one is Static and second is non static, When I am trying to access Static Method it gives me compile time error.

How can I use static method of singleton class?

View 7 Replies

Architecture :: Advantage Of Singleton Class Over Static?

Mar 30, 2010

See in below I have writtine a

1. Singleton class Emp1 with Display Method and
2. Static Class with Static Method Display.

What is the advantage of singleton class over Static Class with Static members?

[Code]....

View 9 Replies

C# - Deallocating Memory, Static Class Destructor?

Jan 13, 2011

I have a static class I'm using as my data layer in my website. In this class, I have string arrays that store queried information that I can access later. Here's the part of my class and the method in question:

public static class data_layer
{
ivate static string[] items;
private static string[] description;
//will return description for an item id. if no item id is found, null is returned
public static string getDesc(string key)
[code]....

View 2 Replies

C# - Get The Name Of The Class Without Instantiating Object Or Having A Static Method?

Feb 22, 2011

I hate to see the name of the class used as a string parameter like "FileDownloader" in the code, and I would like to use something like this FileDownloader.Name(), where FileDownloader is name of the class.
Only problem is that I can't find out how to do that without instantiating object or creating a static method...

Is there a way to get a class name in .net without having the object instance and without creating a static method that returns the name of the class?

View 3 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved