473,671 Members | 2,586 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2050
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("<scr ipt language='javas cript'>\r\n");
sb.Append("func tion ChangeCoords(st rLat, strLong)\r\n");
sb.Append("{\r\ n");
sb.Append(" document.getEle mentById('");
sb.Append(this. txtLat.ClientID "); sb.Append("') = strLat;\r\n");
sb.Append(" document.getEle mentById('");
sb.Append(this. txtLong.ClientI D"); sb.Append("') = strLong;\r\n");
sb.Append("}\r\ n");
sb.Append("</script>\r\n");
this.RegisterCl ientScript("_Pa geScripts", sb.ToString());
}
Hope this helps,
Luke

Jan 31 '06 #2

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

Page.RegisterCl ientScriptBlock 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.my TextBox.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*******@gmai l.com> wrote in message
news:11******** **************@ g49g2000cwa.goo glegroups.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
10097
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, possibly a custom validator with a function written in javascript. Has anyone done this? Does someone have an example? Regards
2
3191
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 the page by the component. However, my javascript gets written to the page before the components javascript, so when my script runs, the textbox being referenced doesn't exist yet.
4
8661
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
3214
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' & 'Cancel'). Till this point, no problem. Initially, the TextBox is empty. The Button has a property named 'ConfirmMessage' so that the developer using this custom control can modify the question in the confirm dialog. If the user clicks 'OK', I want the...
5
13945
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 TextBox I want to use a hidden button to fire when the Onclick Event is fired for the TextBox.
6
4003
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 like that. I'm fairly experienced with ASP.Net, but new to AJAX. Please help if you can. Thanx.
2
13576
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 the contents of a gridview/repeater control? TIA MC
1
7007
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 page has multiple button such login page with a search function somewhere around, then it's not respond properly. I have attached a brief example of two text boxes and two button. When ever a key is press on textbox one, I want to trigger...
6
2895
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") %>' Width="30px" ToolTip='<%# Eval("M1") %>'></asp:TextBox>
0
8402
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8927
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8825
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8605
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8676
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6237
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5703
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4227
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2819
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.