문제

I am passing values generated in C# to my Javascript function like -

C#

 protected int Month;
 protected int Day;
 protected int Minute;
 protected int Hour;

 // set these later in code

Aspx

function test() {

                  Month: '<%= Month%>'
                  Day: '<%= Day%>'
                  Minute: '<%= Minute%>'
                  Hour: '<%= Hour%>'

However as the page reloads when various controls are hit, these variables are being reset to empty. Is there a way I can keep these values so that they are not lost on reload?

도움이 되었습니까?

해결책

You may just define all your fields as properties with values stored in the ViewState, like the example below for Month:

protected int Month
{
    get { return this.ViewState["Month"] != null ? (int)this.ViewState["Month"] : 0; }
    set { this.ViewState["Month"] = value; }
}

다른 팁

You can add the values to a hidden field or some other control on the page that will maintain the value through a page load (through viewstate)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top