gpt4 book ai didi

c# - 当前上下文中不存在文本框

转载 作者:行者123 更新时间:2023-11-30 22:23:19 24 4
gpt4 key购买 nike

我的代码有问题。下面是一个简单的例子,没有很多不必要的 html 标签。只有重要的事情,才能表现出问题。

当我进入页面时,出现以下错误:

Error creating usercontrol (usercontrols/own/profilEdit.ascx)
c:\inetpub\wwwroot\umbraco\usercontrols\own\profilEdit.ascx(705): error CS0103: The name 'satbCountry' does not exist in the current context


此错误与 <script> 有关代码(无论如何这个js代码是正确的,在另一个子页面上工作完美,但是当这个代码在页面上时,它会崩溃)。为什么我会收到这条消息?



这里的代码:

                <asp:View ID="vSpecialist" runat="server">

<asp:UpdatePanel ID="UpdatePanel3" runat="server">
<ContentTemplate>

(..)

<asp:ListView runat="server" ID="lvAddressess" ItemPlaceholderID="phAddress" OnItemDataBound="lvAddressess_ItemDataBound">
<LayoutTemplate>
<asp:PlaceHolder ID="phAddress" runat="server"></asp:PlaceHolder>

</LayoutTemplate>
<ItemTemplate>
<script>
var input = document.getElementById('<%=satbCountry.ClientID %>');
var options = {
types: ['(regions)']
};
var autocomplete = new google.maps.places.Autocomplete(input, options);

</script>
<asp:TextBox CssClass="textbox" type="text" runat="server" ID="satbCountry"></asp:TextBox>

</ItemTemplate>
</asp:ListView>


</ContentTemplate>
</asp:UpdatePanel>

</asp:View>

最佳答案

我认为这是因为satbCountry在模板中定义(即可以重复多次)。获取 clientID对于此控件,您需要使用服务器端代码定位每个实例(例如使用 FindControl("satbCountry"),然后获取客户端 ID。

简而言之,您需要删除 document.getElementById('<%=satbCountry.ClientID %>');用于加载页面,然后替换为

document.getElementById('<%# Container.FindControl("satbCountry").ClientID %>');

关于c# - 当前上下文中不存在文本框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13441270/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com