C# Asp.Net Control.ClientID返回对象而不是字符串

C# Asp.Net Control.ClientID返回对象而不是字符串,c#,asp.net,.net,C#,Asp.net,.net,有时在asp.net中,Control.ClientID返回整个控件对象,而不是ClientID字符串。到目前为止,我还没有太多地关注它,因为我可以用ClientID.Id在客户端搜索它。但是现在我需要传递一个iframe的ID,IE不允许我传递iframe对象,所以这次我必须得到ID的字符串 iframe: <iframe ID="VideoFrame" runat="server" class="embed-responsive-item" frameborder="0" allowf

有时在asp.net中,Control.ClientID返回整个控件对象,而不是ClientID字符串。到目前为止,我还没有太多地关注它,因为我可以用ClientID.Id在客户端搜索它。但是现在我需要传递一个iframe的ID,IE不允许我传递iframe对象,所以这次我必须得到ID的字符串

iframe:

<iframe ID="VideoFrame" runat="server" class="embed-responsive-item" frameborder="0" allowfullscreen src="https://www.youtube.com/embed/" ></iframe>

<asp:Literal runat="server" ID="YouTubeScript" />

代码隐藏:

YouTubeScript.Text = @"
            <script type='text/javascript'>
                $(function() {
                    " + Helpers.CallJavascriptFunction("InitYoutubeVideo", VideoFrame.ClientID) + @"
                });
            </script>
        ";
YouTubeScript.Text=@”
$(函数(){
+Helpers.CallJavascriptFunction(“InitYoutubeVideo”,VideoFrame.ClientID)+@
});
";
更新/回答
我需要将
VideoFrame.ClientID
用引号括起来,以便javascript/jquery将其识别为字符串。否则它会看到该id并将其转换为属于该id的html对象。

看起来您试图以某种方式混合javascript和内联aspnet代码。应该是这样的:

<script type="text/javascript">
    Helpers.CallJavascriptFunction("InitYoutubeVideo", "<%= VideoFrame.ClientID %>");
</script>

CallJavascriptFunction(“InitYoutubeVideo”,”);

您有两个选择。正确使用客户端ID:

<script type='text/javascript'>
    $(document).ready(function() {
        InitYoutubeVideo('<%=VideoFrame.ClientID%>');
    });
</script>

$(文档).ready(函数(){
InitYoutubeVideo(“”);
});
或者将客户端id设置为静态:

<iframe ID="VideoFrame" runat="server" ClientIdMode="static" class="embed-responsive-item" frameborder="0" allowfullscreen src="https://www.youtube.com/embed/" ></iframe>

<script type='text/javascript'>
    $(document).ready(function() {
        InitYoutubeVideo('VideoFrame');
    });
</script>    

$(文档).ready(函数(){
InitYoutubeVideo(“视频帧”);
});

ClientID是一个字符串属性,因此从技术上讲这是不可能的。我已经更新了我的codebehind,以显示js代码段是asp Literala的文本,在这种情况下,它是有意义的。但是,正如@hardkoded已经提到的,代码不会发送对象本身。如果您在
InitYoutubeVideo
函数中出错,则更有意义。通常它只发送ClientID,但出于某种原因,它发送整个控件。在Helpers调用之前,我输入了一个console.log,它记录了iframe本身,
CallJavascriptFunction
中到底发生了什么?它只是一个helper,所以我不必为编写js函数文本字符串而纠结一大堆东西。无论如何,我找到了问题并编辑了我的问题以将其包括在内。谢谢你的帮助!