I want people visiting my web site to have directions to my office using Google Maps, which uses a simple querystring for directions. So on my web site, I want a textbox where a customer can enter where they're coming from, then they either press enter or click a submit button, and then Google Maps should load in a new window.
So I tried this code in the HTML body:
<form runat="server" id="frmMap">
Coming from: <asp:TextBox runat="server" ID="txtComingFrom"></asp:TextBox>
<asp:Button runat="server" ID="btnSubmit" Text="Submit" />
</form>
And I inserted this in the Page_Load:
btnSubmit.OnClientClick = "window.open(' & txtComingFrom.text & "+to+SW1P+2NU');"
When I type a starting location in the text box and press enter (or click submit) then the new window opens ok, but the value of txtComingFrom.text is empty. The strange thing is that if I click submit again (or click in the text box and press enter) then the value of txtComingFrom.text correctly appears. Every time I try this it's the same, clicking Submit once and the textbox value isn't picked up, but if I click it a second time then it is. Why is this?
I have also tried different code:
btnSubmit.Attributes.Add("onclick", IIf(Trim(txtComingFrom.Text) = "", "window.open(' was empty.');", "window.open(' & Trim(txtComingFrom.Text) & "+to+SW1P+2NU');alert('Textbox contains " & Trim(txtComingFrom.Text) & ".');"))
But this alternative code produces the same results, the first click brings up a message "Textbox was empty", and clicking the submit button a second time without reloading or changing anything correctly brings up an alert message with the textbox contents. Why is this?
It seems ASP.net doesn't pick up the textbox value the first time that the submit button is clicked. But it does pick it up when the button is click again. Surely this isn't the way ASP.net was designed? I must be doing something wrong? Can someone please help me here?
So I tried this code in the HTML body:
<form runat="server" id="frmMap">
Coming from: <asp:TextBox runat="server" ID="txtComingFrom"></asp:TextBox>
<asp:Button runat="server" ID="btnSubmit" Text="Submit" />
</form>
And I inserted this in the Page_Load:
btnSubmit.OnClientClick = "window.open(' & txtComingFrom.text & "+to+SW1P+2NU');"
When I type a starting location in the text box and press enter (or click submit) then the new window opens ok, but the value of txtComingFrom.text is empty. The strange thing is that if I click submit again (or click in the text box and press enter) then the value of txtComingFrom.text correctly appears. Every time I try this it's the same, clicking Submit once and the textbox value isn't picked up, but if I click it a second time then it is. Why is this?
I have also tried different code:
btnSubmit.Attributes.Add("onclick", IIf(Trim(txtComingFrom.Text) = "", "window.open(' was empty.');", "window.open(' & Trim(txtComingFrom.Text) & "+to+SW1P+2NU');alert('Textbox contains " & Trim(txtComingFrom.Text) & ".');"))
But this alternative code produces the same results, the first click brings up a message "Textbox was empty", and clicking the submit button a second time without reloading or changing anything correctly brings up an alert message with the textbox contents. Why is this?
It seems ASP.net doesn't pick up the textbox value the first time that the submit button is clicked. But it does pick it up when the button is click again. Surely this isn't the way ASP.net was designed? I must be doing something wrong? Can someone please help me here?