How to share a C# Integer variable with JavaScript

前端 未结 3 1631
死守一世寂寞
死守一世寂寞 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);
            }
    
        }
    
    0 讨论(0)
  • 2021-01-20 15:05

    Have a server side hidden field to hold this piece of information.

    You can access the field through javascript and as a server side control the value will be available server side.

    0 讨论(0)
  • 2021-01-20 15:09

    You need to use some server control to send value back to the server (i.e. asp:HiddenField) or use query string to set the tab index there.

    0 讨论(0)
提交回复
热议问题