• getElementById() dosen't find <input type="hidden" runat="server"/>


    getElementById()  dosen't find <input type="hidden" runat="server"/>

    <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <input id="divPosition" type="hidden" value="12" runat="server" />
    
    
    <div id="divScroller" style="overflow:scroll; margin-top:10px; height:505px; 100%" onscroll="GetDivPosition(this)">
    ...
    ...
    </div>
    
    
    ...
    </asp:Content>

    onscroll I am calling Javascript function "GetDivPosition(this)" and trying to save the sroll positon in hidden field. But the javascript function doesn't find the hidden field if I have runat="server"  attribute with hidden field. Here is the javascript function

    function GetDivPosition(divRef)
            {
                //alert(divRef.scrollTop);                        
                document.getElementById("divPosition").value = divRef.scrollTop;
                alert("hidden" + document.getElementById("divPosition").value);
            }

     

    A server contorl inside Content page will have some prefix added to its ID,when it is generated as HTML.so you'll have to access by using its ClientID like this.

    document.getElementById('<%=divPosition.ClientID%>').value=divRef.scrollTop;

    注意:使用<%=divPostion.ClientID%>的时候,这段js不能写在单独的文件中,必须写在aspx文件中才可以.

  • 相关阅读:
    CAP.dll of dotnetcore
    GRPC 高性能 RPC 框架, 服务间通讯
    REST Client
    ERP Export
    ERP Update DataSource
    knockout js
    面试题目总结
    JavaScript Objiects and Prototypes
    PLS-00172: string literal too long
    字符串连接性能
  • 原文地址:https://www.cnblogs.com/hongjiumu/p/2670036.html
Copyright © 2020-2023  润新知