C# - Declaring A Global Variable In Codebehind?

Mar 18, 2011

I want to declare a Dictionary<string, object> variable but don't know where/how to. The values in the dictionary will be objects from the Page (ListBoxes, DropDownLists, etc) so I can't exactly create a class somewhere else. Is there any way I can make this variable accessible from each method in the codebehind?

View 5 Replies


Similar Messages:

C# - Declaring Global Variable/class In Application Scope 3 Ways - Which One Is Best

Mar 3, 2010

I am looking for differences between those 3 ways of using static class in asp.net application scope.
Will all of these point to the same class?

Which one is preferable >object< defined declaratively inside global.asax or static class ?

examples:

<object runat="server" scope="application" class="classname" ID="objID"></object>

VS

public static class classname {}

VS

Application("a") = new classname();

View 1 Replies

How To Access Javascript Global Variable From Codebehind

Jul 15, 2010

get the value of Global variable in javascript example var a="priti"so want to access "a" in code behind as it's global varible

View 2 Replies

Declare Variable In C# / Use VAR (explicit Declaration) Or The DataType When Declaring A Variable (implicit)?

Sep 7, 2010

Possible Duplicate: Use of var keyword in C# Hi, I am pretty new in C#,I would like to know the best practices in declaring variables.I know it is possible to use VAR (explicit declaration) or the DataType when declaring a variable (implicit).

View 3 Replies

Web Forms :: Declaring The SqlConnection And SqlCommand Objects Without CodeBehind?

Sep 11, 2010

Declaring the SqlConnection and SqlCommand objects in a webform without CodeBehind I am trying to query data from a MS SQL server with a C# web form without "CodeBehind". I want to write the information to a table in the web form's body.

I am having trouble declaring the SqlConnection and SqlCommand objects that connect to the server.

How do you use "using System;", "using System.Data;", "using System.Data.SqlClient" inside the script element of an .ASPX file?

(code below)

[Code]....

View 5 Replies

Declaring Scalar Variable

Jan 23, 2013

I have a really simple web interface which has been created in visual studio 2010 and is connected to an SQL server running MS SQL Server 2008. I essentially want the user to be able to enter values into the two text boxes provided and when the button is clicked, these values are inserted into the relevant table in the database.

When I run the code, I get an error back saying that the 'scalar variable for @clientName is not defined.' I have altered the insert statement to fixed values rather than entering from the text boxes and this works fine (ie, replace @clientName and @serverName in the insert statement with 'xx' and 'yy' respectively). How I can define these scalar variables. I'm not to sure what i'm missing. Code below.

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default2.aspx.vb" Inherits="Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">

[Code] .....

The code that the button executes is below

Partial Class Default2
Inherits System.Web.UI.Page
Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
SqlDataSource1.Insert()
End Sub
End Class

View 3 Replies

C# - Dictionary Lookup Efficiency & Request Scoped Global Variable Accessible By Global.asax And Pages/etc?

Feb 8, 2011

I know there is a couple answered questions on here regarding "request scoped" globals, but I want to nit-pick on something specifically and maybe squeeze some extra enlightenment out of one or two of you.I have an ASP.NET C# Website and a static Dictionary of objects (loaded from DB once on Application start). Each page request will need to do a lookup in the Dictionary (based on a key derived from the request url/etc) and get the appropriate object.The issue is I'm trying to maximize efficiency by reducing the lookups to the Dictionary per Request. Doing just a single lookup within a Page itself is easy enough and I can pass the object to sub controls, etc too.. but global.asax is separate from the Page and it also needs to use the object (in Application_BeginRequest and Session_Start).

So is doing a Dictionary lookup once in Application_BeginRequest, once (when necessary) in Session_Start and once in the Page negligible speed wise, even if there are many requests coming in every second?I would like it if I could just have a Request scoped global variable that I can easily call upon.. the only one I see available though is HttpContext.Current.Items and that is a Dictionary itself.Am I beingridiculously nit-picky with my concern over efficiency? or will these milliseconds (nanoseconds?) get me in the long run when more and more requests are being made?

PS. I currently only have around 100 objects in the Dictionary although this may increase in the future.

View 2 Replies

SQL Server :: Declaring Variable In Stored Procedure?

Feb 16, 2011

I have this procedure

[Code]....

I don't know what variable should be put in where clause for tblVisitor.visitorID because there's a variable that was already passed by an output identity parameter by a different stored procedure. What will I put in the where clause for visitor id?

View 3 Replies

JQuery :: Grab A Global Variable Or Session Or View State Variable In The Javascript?

Dec 9, 2010

can we grab a global variable or Session or View State variable in the javascript or using jquery?

View 2 Replies

Declaring A Constructor Private Or Declaring A Class Sealed Is Same Thing?

Oct 12, 2010

Is declaring a constructor private or declaring a class sealed is same thing?

View 1 Replies

Which Is The Best Usage Session Variable Or Global Variable

May 25, 2010

I have the dataset. in this i am having total 20 tables with huge amount of data..I want use this data over all the page..so where i can keep this data..

before i used viewstate but the viewstate data is render to page every postback ..so this time the page size is increasing(interanlly viewstate is rendered to page)..so performence wise it was very slow..

Now i change my logic insted of viewstate to i used Globel Dataset on Page Level.. now the performence wise better than viewstate..

i used Like shared dsControls as Dataset at top of the page..so every time i use this dataset..

my quesation is session is better or Globel variable is better way use in my situavation..

View 3 Replies

New To C# And Trying To Use A Global Variable?

Mar 11, 2010

Is it possible to use global variables in C#? I'm coming from mainly a PHP background so variables are either accessible everywhere or just a global definition away.

My main issue is I have a User class that I built myself to wrap around the current users table on my company's database. I am defining it in the MasterPage but can't seem to access it from the actual pages (I don't know if there's a better word to describe them but they are the pages that inherit the styles and format from the MasterPage) Any general tips or implementation practices for me?

EDIT: here's some code snippets of what I'm trying to do:

Site.master.cs

public partial class SiteMaster : System.Web.UI.MasterPage
{
public User user = new User();
}
logout.aspx
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="logout.aspx.cs" Inherits="logout" %>
<%@ MasterType virtualPath="~/Site.master"%>
logout.aspx.cs
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
User user = Master.user;
}
}

View 7 Replies

ASP.NET MVC: Is Is Possible To Set A Global Variable

Dec 28, 2010

I have a process within my MVC 2 application that takes a large amount of time and alters many rows in the database in the process.

There is a chance that two or more users could attempt to perform this action at the same time, which would lead to undesirable effects.

Is there a way to set a global flag somewhere within asp.net that I can check against all requests to see if the action in question is currently being executed? (a bit that I flip prior to running query, and then then flip back on completition)Or is there a better way of handling this situation?

View 2 Replies

Variable Scoping On Codebehind In C#?

Mar 17, 2011

I have an asp.net page (C# codebehind), and in page_load there are various linq queries returning anonymous types, such as:

var customersAdded = from r in AddedRecords
select new { Ref = r.CustomerRef, Name = r.Customer_Name };

On the page I have a button called 'export to excel', and in that buttonClick event I try to refer to customersAdded. It says it doesn't exist in the context. I know I've overcome similar issues in the past using things along the lines of:

if (File.Exists(System.Web.HttpContext.Current.Server.MapPath("~/App_Variants/" + GetUserTheme().ToString() + "/images/" + i.ImageUrl)))

So question is, how to refer to the variable? And for reference, if I say wanted to refer to a value in a control (eg a textbox on the page) would the same or different approach apply?

View 1 Replies

C# - How To Define A Global Variable In Web App

Nov 13, 2010

I want client access a data center but without use database , so I want my web app can retain a global or Application session variable, that contains the data, every client can access the same data... I am try to declare in golabl, but seem it only can store String but others ..

View 5 Replies

How To Assign Value To Javascript Variable In C# CodeBehind

Sep 7, 2010

How can i assign value to javasctipt variable from code-behind (C#)?

<script type="text/javascript">
String.prototype.trim = function () { return this.replace(/^s+|s+$/, ''); };
function ConstantByCode(_Obj, _Div) {
var pl = new SOAPClientParameters();
_Obj.value = _Obj.value.trim();
pl.add("Code", _Obj.value);
[code]...

View 4 Replies

VS 2008 Global Variable In Web Service?

Jan 16, 2010

I am having some trouble with my web service. I want to make a variable that will be the same for each thread running. To be specific, my program is that user 1 goes on my page and types something into the textbox and that user 2 can see what user 1 is typing into the box. its sorta like google wave. The problem is that when i run it, the variable's value does not go to user 2 and instead another instance of that variable is created.

View 18 Replies

C# Global Variable Assigned Using Silverlight?

Mar 2, 2010

I'm pretty new to silverlight and asp.net but I have a strong background in c#. I am currently developing a c# asp.net application with silverlight elements. I was wondering if it was possible to have a user say click on an image that has a certain value associated with it and have that value access from a c# variable held outside the silverlight application.

View 2 Replies

C# - How To Declare A Global Variable In MVC Page

Jun 4, 2010

I've began working with asp.net mvc very recently and I've ran into a problem.I've got an aspx page which renders a few ascx pages. What I'd like to do is declare a global var at the aspx page so it is visible to all its childs. I tried <% var i = 0; %> but it wasn't visible at the child pages. What could I do?

View 4 Replies

Global Variable In Master Page

Feb 27, 2013

How do I need get the variable in the master page?

1. after Login.aspx get the information of the user
2. redirect to home.aspx
3. in home.aspx, view the info like Label1.text ="Welcome " + varUser;
4. Label1 is located in the master page
5. this varUser will display in all my pages
6. I don't want to use the full Session["var"] (because of expiration)

*in short I just want to get the var in the master page everytime I load a new page
(WITH MULTIPLE UNIQUE USERS)

View 1 Replies

Web Forms :: How To Read Javascript Variable On Codebehind

Jun 11, 2010

After includeding file.js in ny webpage This script will create a variable within the current javascript context called "Status". This variable can take three values : "On", "Off", "Unknown".How can I read this value on code behind? I am planning to check if the variable is false and if so, make some changes on page.

View 4 Replies

Web Forms :: How To Declare A Global Variable That Can Be Used Within A User

May 15, 2010

I would like know how to declare a global variable that can be used within a user after the user login and before the user logout across all the possible pages.

I need to develop a web application that will connect to 5 different servers depends on the selection of user on what server they wish to connect and after they select a server and login...I will need to keep track the server name in a variable last until the user logout (user may visit various pages but the server name MUST NOT be changed due to other user login into different server). So how can I do it so that other users may select different servers and will keep the server name for each different users.

Let says:-

User A selects Server A and login and User B selects Server B and login at the same time, so how the global variable can handle the needs for each user (User A & B) with different server select?

Is "Session" the only way to fulfill the above? I think of using Application State but it seems that the value stored will be shared by all users and not for a particular user.

View 1 Replies

How To Declare A GLOBAL Variable An Aspx Website

Aug 26, 2010

How to declare a global variable or a public sub in a web application that all aspx pages can have access to?

View 5 Replies

DataSource Controls :: Use Global Variable As A SQL Parameter?

Jan 7, 2010

I need to use a global variable as a parameter for the SqlDataSource element. I capture the user Name when he/she logs in:

Public UserName As String
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
UserName = Page.User.Identity.Name
End Sub

Then, I need to use the UserName to search the SQL DB and show only logged user personal information.

SelectCommand="SELECT * FROM [Member] where [UserID]= UserName"

What is the sintaxe to use a global variable into the SQL Select Command?

View 10 Replies

State Management :: Looking For A Way to Declare A Global Variable?

May 14, 2010

I'm looking for a way to declare a global variable (so all pages could see) but personal (so if one user puts some value in it, it won't matter to another user or change his value).Sessions and hidden fields won't do. I've tried working with declaring keys in Web.config but unfortunely, the keys values aren't personal, and all users share the same key value.Another way I was thinking was maybe classes, but perhaps there might be an easier solution?

View 19 Replies







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