C# - Declare And Create Variable In Code Behind?
Jul 27, 2010
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?
View 3 Replies
Similar Messages:
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
Jan 11, 2010
i want to declare variable for whole of my project , i mean for solution, where and how should i do it?
View 16 Replies
Nov 22, 2015
I 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 Replies
Jan 3, 2011
If ((intCustomerCount Mod intColumns = 0) And (intCustomerCount > intColumns)) Or (intCustomerCount = intColumns) Then
View 3 Replies
May 7, 2010
I 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
View 3 Replies
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
Aug 5, 2010
how to Declare scalar variable
[Code]....
View 6 Replies
Mar 24, 2014
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].....
View 1 Replies
Dec 9, 2010
How to register a Java Script varibale in Server Side (Code behind ) and access at Client side (Javascript file ) , without a hiddenfield , Literal etc
View 4 Replies
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
Oct 21, 2010
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.
View 4 Replies
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
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
Dec 11, 2012
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]....
View 1 Replies
Mar 24, 2011
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]....
View 3 Replies
Mar 1, 2011
I'm getting "Must declare the scalar variable "@ShowTypes"." when I try to run the code below.
[Code]....
View 3 Replies
Jan 2, 2011
i 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 Replies
Jan 14, 2010
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.
View 6 Replies
Mar 28, 2011
OK, this may be a little difficult to explain, so I will try my best and post the code I currently have.
I have a table with a list of usernames. I have the list of usernames displayed on a page through a GridView. What I am attempting to do is for each username in the column "adminUsernames", I need to insert a set of values in another database table for EACH "adminUsernames" that exists. Example: There are 2 adminUsernames vales in 2 seperate rows. These are "Admin 1" and "Admin 2". For each adminUsername values (Admin 1, Admin 2), I need a row interted in another database table. Maybe the code that I have (that does not work) will help you see what is happening:
[Code]....
I keep receiving this error when running: [Code]....
View 3 Replies
Jun 16, 2015
how to declare global variable in master page and use it in all pages
View 1 Replies
Feb 28, 2010
i would like to insert a picture on a gridview, but i allways get the error:
Must declare the scalar variable "@IMAGEM"
somme one can on tihs code ? here is my code:
[code]....
View 13 Replies
May 11, 2010
I am working on this for couple of days but still getting this error message.
SqlCommand sqlInsert;
SqlDataAdapter MySqlAdapter_insert;
SqlCommandBuilder MyBuilder_insert;
[Code]....
View 12 Replies
Mar 16, 2010
I am trying to fill a dataSet with rows from a table in my SQL Server Express 2008 and I keep getting an error.
Error: Must declare the scalar variable "@city".
Code:
using System;
using System.Data;
using System.Data.SqlClient;
[code].....
The error happens at the adCust.Fill command and I am unsure why. If the variable @city was not declared than why did the WriteLine command work.
View 3 Replies
May 18, 2010
I keep getting:
Must declare the scalar variable "@EmailAddress" when I'm debugging and my values aren't being submitted to the DB. Can the eyes of the forum see my error?
[Code]....
[Code]....
View 2 Replies