2

I have a problem with my code. Below is simple example, without a lot of unnecessary html tags. Only important things, to show up the problem.

When I enter page, I get that error:

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


This error is connected with <script> code (anyway this js code is correct, on another subpage works perfectly, but here when this code is on page, it crushes). Why I get this message?



Here code:

                <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>
whoah
  • 4,363
  • 10
  • 51
  • 81

1 Answers1

3

I think this is because satbCountry is defined in a template (i.e. could be repeated many times). To get the clientID of this control you will need to locate each instance using server side code (e.g. using FindControl("satbCountry") and then get the client ID.

In short, you will need to remove document.getElementById('<%=satbCountry.ClientID %>'); for the page to load and then replace with

document.getElementById('<%# Container.FindControl("satbCountry").ClientID %>');
SpruceMoose
  • 9,737
  • 4
  • 39
  • 53
  • thanks for reply. I don't understand - how to remove `document.getElementById('<%=satbCountry.ClientID %>`? What replace with this? – whoah Nov 18 '12 at 15:10
  • Please see this post: http://stackoverflow.com/questions/8919052/how-do-i-find-a-clientid-of-control-in-a-listview – SpruceMoose Nov 18 '12 at 15:16
  • Have modified answer above to include a potential solution. – SpruceMoose Nov 18 '12 at 15:24
  • with your solution, I have error = `error CS0117: 'umbraco.item' does not contain a definition for 'FindControl'` – whoah Nov 18 '12 at 15:32
  • Hmm, think the FindControl would need to be inline within some client even handler on the textbox to work. However I've only tried using 'FindControl' on the data bound event on the server side. What are you doing with the 'autocomplete' var? – SpruceMoose Nov 18 '12 at 17:15