How To Declare A GLOBAL Variable An Aspx Website
Aug 26, 2010How to declare a global variable or a public sub in a web application that all aspx pages can have access to?
View 5 RepliesHow to declare a global variable or a public sub in a web application that all aspx pages can have access to?
View 5 RepliesI'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 RepliesI 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.
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 Repliesi want to declare a variable in page load{} as global so that i can monitor it so that it is not recreated each time
View 4 Replieshow to declare global variable in master page and use it in all pages
View 1 RepliesHow do declare a public variable .aspx web page that can be used in all the pages within my web application? And/or create a Public Sub?
View 3 RepliesPossible 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 RepliesHow do you declare global variables in ASP.NET MVC?
View 6 RepliesI 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.
it's possible to declear global variable in asp.net C#.
View 1 Repliescan we grab a global variable or Session or View State variable in the javascript or using jquery?
i want to declare variable for whole of my project , i mean for solution, where and how should i do it?
View 16 RepliesI heard that Global.asax file is optional in asp.net web application. But, if we need to declare any session variables in my website, do i really need to add Global.asax file and initialize session variables inside Session_Start() ?
View 1 RepliesI 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..
If ((intCustomerCount Mod intColumns = 0) And (intCustomerCount > intColumns)) Or (intCustomerCount = intColumns) Then
View 3 RepliesI have an ENUM shown below that I would like to be able to use on multiple aspx pages. I would like to put it in a class (.vb) file in App_Code
I was not sure of how to declare it in the class file and then how to refer to it on the aspx pages.
Public Enum Slots
NotDefined = 0
Host = 1
Admin = 2
Seller1 = 3
Seller2 = 4
SellersAgent = 5
SellersAtty = 6
End Enum
Here are 3 scenarios:
namespace NS
{
public partial class A: System.Web.UI.UserControl
private Variable v;
protected void Page_Load(object sender, EventArgs e){
if (!Page.IsPostBack) v= new Variable();
....
}
}
namespace NS
{
public partial class A: System.Web.UI.UserControl
private Variable v = new Variable();
protected void Page_Load(object sender, EventArgs e){
}
}
namespace NS
{
public partial class A: System.Web.UI.UserControl
private Variable v;
protected void Page_Load(object sender, EventArgs e){
v = new Variable();
}
}
When does the variable "v" gets created every time for the 2nd scenario? Is the 2st scenario is equivalent to the 3rd one?
how to Declare scalar variable
[Code]....
I Am getting error as Must declare the scalar variable "@Imageid" for the following code,while executing,
exec spGetPager  ' ' , ' ', ' 3 ', ' '
In my coding I pass querystring value like 1,2,3 etc
CREATE PROCEDURE spGetPager
@PageNo int = 1,
@ItemsPerPage int = 1,
@Imageid int,
[Code].....
I am rather confused as how or where to declare this variable in asp.net.
[Code]....
Whenever i put this in my sqldatasource for it is asking me to Define Parameters:
The wizard has detected one or more parameters in your SELECT statement. For each parameter in the Select Statement, choose a source for the parameter's value.
when I am executing an above code and click on button to insert data is shows an error message
as:Â System.Data.SqlClient.SqlException: Must declare the scalar variable "@imagefile"
Protected Sub button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles button1.Click
Try
If fileupload1.HasFile Then
'getting length of uploaded file
[Code]....
I can't figure out whats wrong with my contact page. I am getting this error when executing. It complied fine, I see the page as it suppose to. Then I enter all my contact information and click submit I am getting this error. Can someone guide me. Here is the error msg
must declare the scalar variable @txtSubject Here is the part of relevant code
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
Dim ContactDataSource As New SqlDataSource()
ContactDataSource.ConnectionString = ConfigurationManager.ConnectionStrings("ASPNETDBConnectionString1").ToString()
ContactDataSource.InsertCommandType = SqlDataSourceCommandType.Text
ContactDataSource.InsertCommand = "INSERT INTO Enquery (EnqSubject,EnqFirstname, EnqLastname,EnqContactNumber,EnqEmail,EnqMsg,EnqDateTimeStamp,EnqIPAddress) values (@txtSubject, @txtFirstname, @txtLastname,@txtPhone,@txtEmail,@txtMsg, @txtDateTimeStamp,@txtIpAddress)"
[Code]....
I'm getting "Must declare the scalar variable "@ShowTypes"." when I try to run the code below.
[Code]....
How do I define @UserName in my function:
[Code]....
I believe "UserName" = Me.User.Identity.Name
but I don't know the proper way to add it to the function.