| |

VerySource

 Forgot password?
 Register
Search
View: 737|Reply: 5

Self-increase problem. Trouble everyone to help ..

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-22 08:40:01
| Show all posts |Read mode
I want to increment a variable by 1 when I click a button, and increment it every time I click ... What should I do! Masters ...
Reply

Use magic Report

0

Threads

58

Posts

32.00

Credits

Newbie

Rank: 1

Credits
32.00

 China

Post time: 2020-2-1 03:09:02
| Show all posts
aspx.cs:

public int Counter
{
    get {return (int) ViewState ["Counter"];}
    set {ViewState ["Counter"] = value;}
}

onclick
Counter = Counter + 1
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-2-1 05:45:01
| Show all posts
Variables are defined as static
Reply

Use magic Report

0

Threads

322

Posts

115.00

Credits

Newbie

Rank: 1

Credits
115.00

 China

Post time: 2020-2-1 07:09:01
| Show all posts
On the first floor.

Change it:

public int Counter
{
    get {return ViewState ["Counter"] == null? 0: (int) ViewState ["Counter"];}
    set {ViewState ["Counter"] = value;}
}

Button_Click

Counter = Counter + 1
Reply

Use magic Report

1

Threads

8

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 Ireland

Post time: 2020-2-1 09:27:01
| Show all posts
Ibid
Reply

Use magic Report

0

Threads

43

Posts

29.00

Credits

Newbie

Rank: 1

Credits
29.00

 China

Post time: 2020-2-1 15:09:01
| Show all posts
Save the number of clicks in the viewstate, and the viewstate is incremented by one each
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list