How to share a C# Integer variable with JavaScript

前端 未结 3 1675
死守一世寂寞
死守一世寂寞 2021-01-20 14:31

I want to share the currentTab variable which exists on the C# server side with JavaScript. Here is my code:

C#:

public         


        
3条回答
  •  情书的邮戳
    2021-01-20 14:48

    You can write the index from your javascript function, to a hiddenfield, and then read that on postback.

    In your code, you check the hiddenfield, if your page is postback. Like so:

    protected void Page_Load(object sender, EventArgs e)
        {
            if (Page.IsPostBack)
            {
                currentTab = Int32.Parse(HiddenTabValue.Value);
            }
    
        }
    

提交回复
热议问题