Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Writing to an ASP textbox from javascript

Reply
Thread Tools

Writing to an ASP textbox from javascript

 
 
alanliang@gmail.com
Guest
Posts: n/a
 
      01-31-2006
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

 
Reply With Quote
 
 
 
 
slagomite
Guest
Posts: n/a
 
      01-31-2006
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

 
Reply With Quote
 
 
 
 
sloan
Guest
Posts: n/a
 
      02-01-2006

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.



<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
using asp:textbox as search box, handling enter in textbox Imran Aziz ASP .Net 2 09-05-2005 11:00 AM
ASP.NET textbox loses text value in composite control but Textbox subclass doesn't!? ErwinP ASP .Net Web Controls 1 08-19-2005 01:50 PM
Calendar popup - using ASP textbox instead of HTML textbox =?Utf-8?B?Q2hyaXM=?= ASP .Net 3 03-30-2005 06:02 PM
Asp.net textbox/ access 2002 textbox incompatibility ald ASP .Net Web Controls 3 12-21-2003 07:55 PM
writing two textbox's text in one textbox agb ASP .Net Web Controls 1 08-27-2003 12:57 AM



Advertisments