Question

I have textbox in asp.net where i am writting Address.

On linkbutton below i wanted to direct it to goole map.

I have below textbox:

<asp:TextBox ID="txtJobAddress" runat="server" TextMode="MultiLine" Width="95%" Height="20px"
                        onBlur="javascript:saveChanges('JobAddress');"></asp:TextBox>

Linkbutton as below:

<a href="http://maps.google.com/maps?q=<%=txtJobAddress.Text%>" target="_blank">
                        <img src="images/gmap_button.gif" alt="Map" />
                    </a>

but when its getting directed through anchor tag, its not catching "q" parameter.

Its giving as:

https://www.google.com/maps/preview?q=

why its not taking value of:

<%=txtJobAddress.Text%>

Please help me , how can i attach textbox string here in

http://maps.google.com/maps?q=<%=txtJobAddress.Text%>

as below

http://maps.google.com/maps?q=NewYork

Was it helpful?

Solution

The <%=txtJobAddress.Text%> will be empty on page load. Presumably your saveChanges method prompts an ajax call to save the "JobAddress"? If this is the case then a full page postback won't occur, and therefore the <%=txtJobAddress.Text%> isn't populated with the updated value as this would occur on the server. You'll want to populate the query string value client side

e.g. in your blur event you could add a call to a javascript function that updates your link:

onBlur="javascript:saveChanges('JobAddress'); updateLink()"

in your updateLink function you would update the link query string value

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top