declaring global variables

Partial Class _Default
    Inherits System.Web.UI.Page
    Private nvers As Integer
    Private nid As Integer
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
             nid = 0
        End If
    End Sub

    Protected Sub NewVer_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles NewVer.Click
        nid=1
        nvers=3
    End Sub

    Protected Sub NewOp_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles NewOp.Click
        nid=2
        nvers=3
    End Sub

Protected Sub myWizard_FinishButtonClick(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.WizardNavigationEventArgs)
      
        If nid =1 Then
            'Do something
        End If
    End Sub

But although I click NewVer_click(which sets nid to 1) in myWizard_FinishButtonClick nid remains 0

How should I declare my variable nid to be global?
thanks

0
engnouna
3/22/2007 9:22:12 AM
asp.net.web-forms 93655 articles. 6 followers. Follow

5 Replies
538 Views

Similar Articles

[PageSpeed] 40
Get it on Google Play
Get it on Apple App Store

Try this:

Application["NidVar"] = nid to save the nid value

 and cast nid = (int) Application["NidVar"] to get the value back.

 


Trirange Portal Server Online Demo
http://www.trirange.com/demo/
0
upgView
3/22/2007 10:43:55 AM

I think that cast nid = (int) Application["NidVar"]  is a C# code

can you give it to me in VB code?

thanks

0
engnouna
3/22/2007 10:49:37 AM

Global variables cannot be considered this way in asp.net, since it works a stateless manner. Any private variables that you set in your _Default class will be lost at each page roundtrips.
I think you may want to read a little bit more about the way ASP.NET is processed code behind pages.

You may want to use Session or ViewState variable capabilities instead. Session is a collection that is used to store values for a authenticated user. Try this instead of private nid declaration :

private int nid
{
    get { 
            if (Session["nid"] == null)
                return 0;
            else
                return (int) Session["nid"];
        }
    set {
            Session["nid"] = value;
        }
}
I'm sorry, this is C#. I do not have Visual Basic installed on my box. The conversion is easy.
Good luck- 
0
CtrlBr34k
3/22/2007 10:49:40 AM

Thanks to this, here is the VB version :

Private Property nid() As Integer
	Get 
            If Session("nid") Is Nothing Then
                Return 0
            Else 
                Return CType(Session("nid"), Integer)
            End If
	End Get
	Set (ByVal Value As Integer) 
            Session("nid") = value
	End Set
End Property
Application or Session variable ? That depends if the process you intend to use in your Web application is application dependant or user dependant.
Good luck
0
CtrlBr34k
3/22/2007 1:28:45 PM

Partial Class _Default
    Inherits System.Web.UI.Page
    Private nvers As Integer
    Private nid As Integer
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
             Application["NID"] = 0
        End If
    End Sub

    Protected Sub NewVer_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles NewVer.Click
        Application["NID"] =1
        nvers=3
    End Sub

    Protected Sub NewOp_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles NewOp.Click
        Application["NID"] =2
        nvers=3
    End Sub

Protected Sub myWizard_FinishButtonClick(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.WizardNavigationEventArgs)
      
        If CInt(Application["NID"])Then
            'Do something
        End If
    End Sub

 

If you want your variable scope is over all your application then use Application, else you can use Session. CInt is used to cast to Int type.


Trirange Portal Server Online Demo
http://www.trirange.com/demo/
0
upgView
3/22/2007 1:29:22 PM
Reply:

Similar Artilces:

acessing variables across web forms( a la Global variable)
Hi, I have multiple web forms in my application i want to access some data( from sql database) which is common to all the forms. i want to retrieve the data only once & use it for all the forms. as ther are are no global variables in .net can anyone suggest how i can implement this ? lonewolf If the data is small enough, use the Session. It is like viewstate, but held on the server. To access it, do the following in the code behind: E.g Let's say you want to store login information, i.e. userid. Then... To set the variable (typically done on your login page): Dim useri...

How do you declare a GLOBAL variable in VB.net
Does anyone know how to do this?  Thanks, NewKid Global variables in .net 2.0 dont really exist the way they used to in C++ for example, because you dont have a single instance class running.  If you are in the ASP.NET model, you can use the global.asax file to declare a Public or Public Shared variable, or you can use Sessions as your global variable holder. If you are in a VB model for win forms, Your best bet is to declare a class, and put a public member in it that will hold your value, and instanciate it when the application starts.Bryan SampicaAuction Site StarterKit |M...

Implementing .Net Form into an APS.net web form, can this be done
I am new here, but have been searching for a while, and may not have the correct lingo to find what I am looking for.  I am tasked with implementing a .exe application that was writen vb6 then converted to .net into a new website my team is developing. The idea is to put each of the 3 different forms in this .exe application of 3 different .aspx pages. I have attempted multiple things to get this into the page and even started to just rewrite it as an ASP.net web form, but even then I can't reuse any of the code since the System.Web.UI.Page doesn't inherit the sa...

Global variable declaration in vb.net winforms
Hi all Can anyone please tell how to declare global variable in winform. I want to declare one variable at start of a application and use in different form. eg. i want to store userid/usertype and check in each form this variable across the application. Also please tell me how to use in each form Thanks in advance Rashid Windows Forms forums at http://forums.microsoft.com is more suitable place to ask WinForm related questionsThanks,Teemu KeiskiFinland, EU With Visual Basic, it's fairly easy to create global variables in winforms.  Modules are the usual method.  As long as it...

Acessing variables, objects and functions from javascript to VB .NET Web Forms
I have included some javascript files in my vb.net application. I want to access the variables, objects and functions of Javascript to the VB.NET Web Forms, which means that I want to transfer the methods from Javascript to the code-behind in a web form. How do I do this? Can anybody help me with some sample codes...thanks in advance . you can't pass javascript variables (client side) to code-behind (server side). you can however put your variables into hidden input fields then access those input fields from code-behind. or use ajax I think the only way to do this is...

Acessing variables,arrays, objects and functions from javascript to VB .NET Web Forms
I have a textbox where user can put data.I store data into an array .I did this with java script.now i want to acess the array from the Codebehind  in vb.net web pages.here is the codefunction MakeArray( n ) { if( n <= 0 ) { this.length = 0; return this; } this.length = n; for( var i = 1; i <= n; i++ ) { this[ i ] = 0; } return this; } var Form1 = new MakeArray( 25 ); var index = 0; var cmmnd = 1; function f_store( sTR ) { var i; if( index >= Form1.length ) { for( i = 1; i < Form1.length; i++ ) Form1[i-1] = Form1; index = Form1.length - 1; } Form1[ index ] = cmmnd + ":" + sT...

windows forms in vb .net into web forms
we are creating a database driven website as part of our project. currently we have forms connecting to the database created in visual basic. these windows forms we need to convert into web forms which are asp .net compatible. can u give me an answer or show me a way. Hi, because of the difference in nature between web and win applications you'll need to reimplement at least the UI part. If you have a multitiered application in which the busines logic and data access are in different parts/assemblies you can reuse them. Grz, Kris.Read my blog. Handy Firefox plugins for web developers.Wor...

Web Part, Web Request, and HTML form Variables
I would like to build a web portal to display existing standalone web sites in separate web parts.  I was thinking I would need to use an IFRAME in a web part or have the web part do a web request and display the web response.  I would like to be able to monitor the http traffic between the web part and the existing web sites server so that I can perform additional processing on my server. Is there a way that I can capture (read only) the form variables/ hyperlink address when a user clicks a form submit button or hyper link in a web part that has an IFRAME? What if I used the w...

.Net Web Form & Web Service Deployment
Hi all I have written some test web services and some web form applications and deployed them to my IIS. That's fine but I now want to deploy them to my real IIS server. I have created an msi for each but the problem is I seem to only be able to deploy to the default web site. Our default web site is turned off and instead we use several other sites. Does anybody happen to if Powerbuilder 11 supports non default web sites? If not do I need to hack the msi and if so can anybody suggest a suitable tool. I have Orca but it's not very friendly. Unless of course I knew exactly w...

Declaring Global Variables and Global External Function By PowerScript
Does anyone can tell me, can I declare the global external function / global Variables by PowerScript ( such as, within the application's open event ), not in 'declare painter' ??? Thanks Samkola No. They need to be declared within the Global Variables painter. Ron Gallagher, CPDP Atlanta, GA rongallagher@mindspring.com samkola wrote in message <01beee19$8715d2a0$2d01a8c0@testing>... >Does anyone can tell me, can I declare the global external function / >global Variables by PowerScript ( such as, within the application's open >event ), not i...

How to Make Web Forms from other Web Forms
In putting together an ASP.NET application for a biz application, we have come to the point where there are three different types of basic forms which have, for the most part, been perfected. Now its is a matter of cloning those forms for various uses and modifying or adding code to suit the particular need. Copy and paste works OK, but there is a lot of changing of certain words, etc. Is there a way in ASP.NET to take these basic forms, turn them into classes or templates, create forms from them, then add or overwrite code? ? (Anybody who is a Vis Fox Pro programmer would know imme...

Web forms and mobile web forms
Hey everyone, I am looking to develope a web site that depending on the device connecting to it, it will display a certain page. In this case im looking to create a web and wap version of the same project. I have the Web forms version finished using ASP.NET and C# and I am wondering how to create the mobile web form and incorporate it in the project. In the project folder, can I just add a mobile web??? But what about displaying device specific pages?? Cheers -Dudach Yes, you can add mobile web forms and controls to your Web Application project. No problem. For device/br...

Quickie question: Declaring a global-level variable with Global.asax
My instructor told me it might be best to create an SQL connection in global.asax instead of making new connections for every form I create. However, when I declare the variable in Session_Start, it still doesn't see the variable on the other form I have. Obviously there is something I'm not getting here. So my question might sound trite, but I simply need to create an SQL connection variable that can be accessed from any of my .aspx pages. Any takers? Your professor does not understand ASP.NET and connection pooling. Creating a single connection in Global.asax and using it on ...

Global Variables vs. instance variables declared at application object level
There is only one application object instance during the application runtime that is instantiated at the start along with the global variables, so I am looking for what are the major differences, advantages , and disadvantages between Global Variables and instance variables declared for the application object. Thanks I've wondered also about the application instance variables. I think the difference with global vars is very subtle. Maybe too subtle to be of any use. Anyway, you shouldn't be using either one of them :-) Geert 'Darling' Van Damme Moh...

For interrupting.web form Resized by position of the div : if div can't dispaly all (such as only top part , then web form heithten the heght),resize the web form
Web Form Resized by position of the div : if div can't dispaly all (such as only top part , then web form heithten the heght),resize the web form ! Because of my pool English, if you can't see , I will explain more ! ThanksGambler is the real life I guess you mean when form grows it also grow parent div element. This is normal. If you want div to stay fixed size and rather clip the form and maybe show a scrollbar, look at overflow property in CSS.Thanks------------------------------------------------------------This posting is provided "AS IS" with no warranties, and confers no ...

Web resources about - declaring global variables - asp.net.web-forms

Anonymous declaring war on Singapore Government - YouTube
Anonymous declaring war on Singapore Government Greetings Government of Singapore, We are Anonymous and we believe that we have your undivided ...

Man Haron Monis ordered chocolate cake and a cup of tea before declaring, 'I have a bomb', inquest hears ...
At first, he appeared to be just another person wandering through Martin Place on a sunny Monday morning.

Most ACT Assembly members not declaring or using frequent flyer points
Most Assembly members are not declaring frequent flyer points and fewer still are using the points to offset the cost of flying

Eddie Hayson: How one of Australia’s biggest punters lost a $52 million bet — declaring himself insolvent ...
BROTHEL owner Eddie Hayson is on the brink of bankruptcy after declaring himself insolvent with $52 million in debts.

Malcolm Turnbull breaks ranks on citizenship, declaring constitution cannot be compromised
Malcolm Turnbull has declared official efforts to protect national security and prosecute the war on&nbsp;terrorism must not be allowed to erode ...

Odessa buries its dead, declaring 'never forget, never forgive'
Under thunderous skies, several dozen mourners could contain themselves no longer, bursting into chants of "Glory to the heroes" as the coffin ...

Shorten's delay in declaring
OPPOSITION Leader Bill Shorten failed to declare tens of thousands of dollars in political donations he received in the lead-up to the 2007 election ...

Humankind loves declaring 'war' on everything and now we have the data to prove it
You could be forgiven for thinking we live in a time of escalating conflict. But there's some good news, based on a new unique language analysis. ...

Great Barrier Reef: World Heritage Committee decides against declaring reef as 'in danger'
The United Nations' World Heritage Committee decides against declaring the Great Barrier Reef in danger.

Emails show UN health agency resisted declaring Ebola emergency
Internal emails and documents obtained by The Associated Press show that the World Health Organization resisted sounding the international alarm ...

Resources last updated: 12/28/2015 2:51:49 PM