473,382 Members | 1,736 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Writing to an ASP textbox from javascript

I want to be able to populate an asp textbox with logitude and
lattitude values whenever a user selects a point or creates a marker on
google maps. Simply, how do I change an asp's textbox value through
javascript?

Thanks,

Alan

Jan 31 '06 #1
2 2028
In general, you'll have to generate the client-side code on the
server-side (e.g., in your Page.PreRender handler), in order to
reference the resulting client ID for the textbox. For example:

[HTML]
<asp:TextBox id="txtLat" runat="server" />
<asp:TextBox id="txtLong" runat="server" />

[Code-Behind]
protected TextBox txtLat;
protected TextBox txtLong;
....
private void Page_PreRender(...)
{
StringBuilder sb;

sb = new StringBuilder();
sb.Append("<script language='javascript'>\r\n");
sb.Append("function ChangeCoords(strLat, strLong)\r\n");
sb.Append("{\r\n");
sb.Append(" document.getElementById('");
sb.Append(this.txtLat.ClientID"); sb.Append("') = strLat;\r\n");
sb.Append(" document.getElementById('");
sb.Append(this.txtLong.ClientID"); sb.Append("') = strLong;\r\n");
sb.Append("}\r\n");
sb.Append("</script>\r\n");
this.RegisterClientScript("_PageScripts", sb.ToString());
}
Hope this helps,
Luke

Jan 31 '06 #2

Check out
http://msdn.microsoft.com/library/de...BlockTopic.asp

Page.RegisterClientScriptBlock Method

that is to get the javascript written to the page (when you do a viewsource
on the hmtl page).

You still have to write your script function.
The trick is figuring out what the official name of the text box in the form
is.
The previous post does a good job, using the getElementById method.

you can also do something like

this.frmMain.myTextBox.value;

where frmMain is the name of your form , in your <form name='frmMain'
id='frmMain'> declaration.

Aka, getElementById is probably better, but just showing you how you might
hard reference it.

<al*******@gmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
I want to be able to populate an asp textbox with logitude and
lattitude values whenever a user selects a point or creates a marker on
google maps. Simply, how do I change an asp's textbox value through
javascript?

Thanks,

Alan

Feb 1 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Jerry | last post by:
In limiting textbox input to 500 characters I would like to include a dynamic count of characters input while the user is typing into a textbox. This would obviously be a client side control,...
2
by: Mark | last post by:
Hi - I have a component, which sends some Javascript to the page. I have a registerclientscriptblock which writes some Javascript which when the page is loaded, references a textbox written to...
4
by: Dabbler | last post by:
Is there a way to mark the text in a TextBox control as selected so when the user types a new value the existing text is replaced? Thanks
1
by: rn5a | last post by:
I want to create a custom control that encapsulates a Button & a TextBox. When the Button is clicked, the user is asked a question using JavaScript confirm (which shows 2 buttons - 'OK' &...
5
by: Stuart Shay | last post by:
Hello All I am working on ASP.NET 1.1 Custom Pager that allows a User to Enter a Number in a TextBox and go to the page selected. Since the OnClick Event does not work in ASP.NET 1.1 for a...
6
by: HockeyFan | last post by:
I'd like to have an AJAX textbox that after the user fills in, will auto-fill another textbox on the page without having a postback occur. It doesn't have to do any filtering or any other thing...
2
by: mc | last post by:
Can someone suggest how I would add a new trigger such that when the JS event onkeyup in a textbox the updatePanel refreshes? If not could someone sugest how I could onkepup in a Textbox, refresh...
1
by: daonho | last post by:
I tried to use javascript to trigger up the button click function when user press enter key from the textbox. This function work fine with a single button click such has login page. However, if the...
6
by: john | last post by:
I have the following textbox setup with Text & ToolTip Bindings as follows; I'm using Visual Studio 2008 VB: <asp:TextBox ID="txtDay1" runat="server" Text='<%# Eval("Day1") %>'...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.