ASP.NET Adding Numbers

Posted on 2006-05-04
Last Modified: 2008-03-17

real quick one. I have made this quick script that simply adds one to a public integer. I then write it to screen. This is triggered by clicking a Linkbutton.

I think the code is fine but it is not adding one to the value, or it is not displaying the most recehnt value

Thanks in advance


    protected void HyperLink1_Click(object sender, EventArgs e)
        MyValue += 1;
Question by:REA_ANDREW
    1 Comment
    LVL 52

    Accepted Solution

    How have you declared MyValue ? If it is simply a public field in your page then it will not retain its value between posts. You would need to store the value in the session, or the viewstate, or somewhere else with a more persistent scope.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Suggested Solutions

    Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
    This demonstration started out as a follow up to some recently posted questions on the subject of logging in: and…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now