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> 

1 Answer 1

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 %>'); 
Sign up to request clarification or add additional context in comments.

5 Comments

thanks for reply. I don't understand - how to remove document.getElementById('<%=satbCountry.ClientID %>? What replace with this?
Have modified answer above to include a potential solution.
with your solution, I have error = error CS0117: 'umbraco.item' does not contain a definition for 'FindControl'
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?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.