Is there a way to use “<%= someObject.ClientID %>” in an external javascript file?

前端 未结 8 1265
隐瞒了意图╮
隐瞒了意图╮ 2020-12-04 15:28

Is there a way to use \"<%= someObject.ClientID %>\" in an external javascript file?

If I use the code

<%= someObject.ClientID %>
         


        
8条回答
  •  情深已故
    2020-12-04 16:31

    This adds a bit more HTML but it works; wrap each server control in a div...

    Set the HiddenField's value in the code behind

    hdMyControl.Value = "something";
    

    Then in your external JS file you can get the server control's value

    $(document).ready(function () {
        var myValue= $('#myContainer input[type=hidden]').val();
    

    I'm not sure that it matters, but I'm adding the script reference to the page via the codebehind using RegisterClientScriptBlock

提交回复
热议问题