0

如何从后面的代码 (C#) 访问和使用 javascript 变量。经过研究,我实现了访问变量的过程,但我仍然没有得到变量的值。我哪里错了?

 //Javascript
    <script type="text/javascript">
    function OnSucceeded() {            
        var status = 65;
        var state = "pass value"
        document.getElementById("getValue").value = status;
        document.getElementById("getvalues").value = state;
    }
</script>


//
  <asp:HiddenField ID="getValue" runat="server" Value="" />
  <asp:HiddenField ID="getvalues" runat="server" Value="" />

    <asp:Button ID="Button1" runat="server" OnClientClick="OnSucceeded()" Text="Button"
        OnClick="Button1_Click" />

 //C# code behind
  ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" +    getvalues.Value + "');", true);
4

1 回答 1

0

使用 ClientID 呈现服务器控件的正确 ID

<script type="text/javascript">
    function OnSucceeded() {            
        var status = 65;
        var state = "pass value"
        document.getElementById("<%= getValue.ClientID %>").value = status;
        document.getElementById("<%= getvalues.ClientID %>").value = state;
    }
</script>
于 2013-06-23T07:38:34.573 回答