Cannot get value from an input textbox to a listbox web control??

I am about to go nuts because I really have not done any Asp.Net programming up until now. I have mainly done desktop applications. I am trying to take the textbox in the page and pass the contents of it to the listbox on the same page. I cannot get the values from the textbox to the listbox. Below is my code for the aspx page and also for my code behind page. Can someone please tell and show me where I am going wrong?

aspx page:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="AspNetPolyDraw.Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>AspNetPolyDraw, Proof Of Concept Application</title>
    
    <!-- Must use UTF-8 encoding to draw certain elements of the map. -->
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <!-- Make a reference call to the VEMap control. -->
    <script type="text/javascript" src="http://dev.virtualearth.net/mapcontrol/v4/mapcontrol.js">
    </script>
    
    <!-- Javascript functions for working with the mapcontrol. -->
    
    <script type="text/javascript">

        // Draw the map on the webpage.
        function GetMap()
        {
            map = new VEMap('myMap');
            map.LoadMap();
            map.AttachEvent('onclick', GetPointInfo);
        }
        
        // Get the point info where the user clicked on the map and return the lat/long
        function GetPointInfo(e)
        {
            var latlong = "";
            latlong = e.view.LatLong.Latitude + "," + e.view.LatLong.Longitude + "*";
            //__doPostBack('__Page', 'latlong');
            latlong = latlong + document.getElementById("txtLatLong").value;
            document.getElementById("txtLatLong").value = latlong;
            //document.getElementbyID("txtLatLong").value = latlong;
        }
    </script>
    
       
    
</head>
<body onload="GetMap();">
    <form id="form1" runat="server">
        <div id='myMap' style="position:relative; width:400px; height:400px;">
        </div>
        <br />
        <input id="txtLatLong" style="width: 400px" type="text" /><br />
        <br />
        <asp:Button ID="btnDone" runat="server" Text="Done Drawing" Width="400px" OnClick="btnDone_Click" /><br />
        <br />
        <asp:ListBox ID="ListBox1" runat="server" Width="400px"></asp:ListBox><br />
        <hr />
    </form>
</body>
</html>
 
code behind:
 
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace AspNetPolyDraw
{
    public partial class Default : System.Web.UI.Page
    {

        protected string PostBackString = "";

        
        protected void Page_Load(object sender, EventArgs e)
        {
            PostBackString = Page.ClientScript.GetPostBackEventReference(this, "MyArgument");

            if (Page.IsPostBack)
            {
                string eventArg = "";
                eventArg = Request["__EVENTARGUMENT"];
                if (eventArg == "latlong")
                {
                    //
                }
            }

        }

        protected void btnDone_Click(object sender, EventArgs e)
        {

            ListBox1.Items.Clear();

            for (int x=1; x < 6; x++)
            {
                ListBox1.Items.Add(Request.Form["txtLatLong"]);
            }
        }
    }
}
 

 

Thanks in advance,

nb



Noble D. Bell
www.noblebell.com
0
Noble
4/18/2007 4:29:51 PM
asp.net.web-forms 93655 articles. 5 followers. Follow

5 Replies
1064 Views

Similar Articles

[PageSpeed] 15

Hey there!

Instead of using a HTML <input tag, why not use an <asp:TextBox 

<asp:TextBox ID="txtLatLong" runat="server"></asp:TextBox>
 

That way, you can get its value like this...

ListBox1.Items.Add(txtLatLong.Text);
 
"A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools." ~ Douglas Adams

http://pixelsyndicate.com/ps/
0
pixelsyndicate
4/18/2007 5:34:12 PM

If I do that, then it brings the question of how to get the JavaScript variable to the txtLatLong asp:Textbox?

 

Forgive me for being so green here -- I just don't do that much web programming.

 

Thanks in advance,

nb

 



Noble D. Bell
www.noblebell.com
0
Noble
4/18/2007 6:09:43 PM

the asp:TextBox translates itself into HTML, so your clientside code will see a basic INPUT field.

This ...
< asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
translates into this...
< input name="txtLatLong" type="text" value="Value" id="txtLatLong" />


"A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools." ~ Douglas Adams

http://pixelsyndicate.com/ps/
0
pixelsyndicate
4/18/2007 6:22:38 PM

Here is code that shows basically what you can do. The key is the ClientID of the control. You have to use it because that is what is rendered to the client. You just have to write it out for the javascript to use. For youe text box do something similar. Then you can jsut the normal object model for accessing the value entered in the text box.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm3.aspx.cs" Inherits="ASPNETForumResponse.WebForm3" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body onload="FillTextBox()">
    <form id="form1" runat="server">
    <div>
    <asp:TextBox ID="MyTextBox" runat="server"></asp:TextBox>
    </div>
    </form>
</body>

<script type="text/javascript">

function FillTextBox()
{
    document.getElementById('<% Response.Write(MyTextBox.ClientID); %>').value = "myValue";
}

</script>

</html>
 

 

 

 

0
jdaresta
4/18/2007 6:25:11 PM
Noble Bell:

If I do that, then it brings the question of how to get the JavaScript variable to the txtLatLong asp:Textbox?

Sorry Nobel Bell, I pasted the wrong line...

<

asp:TextBox ID="txtLatLong" runat="server"></asp:TextBox>
translates into HTML and becomes
<input name="txtLatLong" type="text" id="txtLatLong" />

"A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools." ~ Douglas Adams

http://pixelsyndicate.com/ps/
0
pixelsyndicate
4/18/2007 6:29:59 PM
Reply:

Similar Artilces:

How to get the HREF value of the Anchor tag in a web page using the web browser control in vb.net
Hi Friends,               i have a webserver control in my application.i load the web browser control on a button click using the below code Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click                AxWebBrowser1.Navigate("http://www.rateitall.com/i-322335-.aspx", False) End sub once the page is loaded in the browser i want the <a> HREF value in that page.For example if that page has ...

Clearing Web Controls Values from a Web Form
I have a web form and after a user submit it I want to clear the form so that they may submit another entry. I have seen examples in VB of how to loop thru a web form and clear the controls, but I need a C# solution. I have tried the following code, while it does not give me an error, it does not clear the controls on the form. Any suggestions? Thanks! foreach (Control parent in Page.Controls)         {             foreach (Control child in parent.Controls)           ...

validate Textbox in Web User Control from web form?
ASP.NET 2.0 I have a web user control that contains a textbox.  I need to add some validation (like requiredfieldvalidator, comparevalidator, etc). I would normally add the validator to my web user control by placing the validator next to my textbox.  However, I need the validation message somewhere else on my web form, not near the user control. So how would I associate a validation control on my web form with the text box inside my web user control?  Can this be done; any alternatives out there? Thanks!   The error message should occur wherever you place the vali...

Get listbox value from the other web form
 Dear all, I want to get the lisbox selecteditem value to a textbox in one web form from the other web page. Should I use session to get this value?Can any one help in this regard? Thanks a lot in advance.  People Develop People Yes you can use Session to get the informations between cross pages.. see below for your referenceTO STORE THE INFO in Session Session["key"] = ListBox1.SelectedItem.Value; Response.Redirect("Page2.aspx");TO GET THE VALUES FROM Sessionprotected void Page_Load(object sender, EventArgs e){    if (Sessio...

Controlling web control instances on Web Form
I have created a composite control, extending functionality of the Hidden Control. However, I would like to prevent the user from adding this control to the page multiple times. I only want one instance of the control on the Web Form. What setting in my project to I adjust to enable this functionality? I can not find it in any of the books that I have referenced. Is this a setting or is this code that has to be added to the inheriting class. Looks like there is no standard apporach. But I'd consider using static field to count number of created objects and throw exception if second object ...

Retreiving a value from a web form within a web user control
Hi  I have a page (web form) that retreives some data from a database. To be more specific: at some point when user clicks a button (in the web form) there is some ID number retreived from a database in code behind. At the same time the Visible property of the nestet web user control is chamged to true. I want than forward the ID to the web user control so that a grid view can load data from a database for that ID. How can I access that data (the ID) within a web user control context nested in that page?  Kind regards   Check this ;ink  http://www.codeproject.com/K...

How to get Textbox value in web user control?
Hi friends,I created a web user control with only one textbox.(textbox.ascx) and textbox id=" txtSimple"textbox user control having some property. another user control with button(button.ascx) next i use two textbox usercontrol and one button usercontrol in sample.aspx. when i click button at that time call the required field validate property in textbox user control.in property have following code.public bool RequireValidate    {        set        {     &nbs...

Filling a textbox on a parent web user control from a child web form
Hi, I currently have a web user control (pf_imageselector.ascx) which is dynamically created (any number of times) on a parent web user control (pf_fillitems.ascx) which in turn has been loaded into a webform (default.aspx). On the user control is a text box called txbSelectedImage and a button. On click of the button run's this code: function OpenChild() { var strImageFile; var WinSettings = "height=580,width=630,status=yes,toolbar=no,menubar=no,location=no"; window.open("pf_stockimage.aspx", null, WinSettings); } Which obviously open a ch...

web web web
Name: bahadir Email: sensiz_olmuyor_t1_at_hotmail.com Product: Firefox 2 Beta 2 Summary: web web web Comments: web sayfası yapmak Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; tr; rv:1.8.1b2) Gecko/20060821 Firefox/2.0b2 ...

Passing Values from a Web Form to Another Web Form
Hello All! I am trying to pass values from one web form to another web form. I know that there are 3 ways of doing this: queryString, Server.Transfer and Session. I am using the Server.Transfer method. But I am not able to create, in my 2nd web form, an instance of my 1st web form. My 1st Web form is named CallTrack.aspx and my 2nd is named Export.aspx. What I mean is something like this: Public value as CallTrack. I can't create it in my 2nd web form because when the intellisense is displayed, there's no CallTrack in the options. Thanks!   How about using cross-...

How to access a control on a web form from anoter web form
hi all I have this scenarios i have two web forms, one called form1 and the other called form2 form1 has a label with id "lbl1" is it possible to access lbl1 from form2, change its text permenantly? thanks.   refer: http://dotnetslackers.com/Community/blogs/haissam/archive/2007/11/26/ways-to-pass-data-between-webforms.aspxSSNPlease remember to click "Mark as Answer" on the post that helps you. MinaSamy: hi all I have this scenarios i have two web forms, one called form1 and the other called form2 form1 has a label with id "lbl1" is it possible to access lbl1 from form2, change its text permenantly? thanks. Hi once you navigate from the page you can only access its properties if you you cant chnage it when you return back the value will again be new one unless you assign it So you can use session variables and set the session variable Session("lbl") = "Hello" Label1.Text = Session("lbl").ToString()   hence whenever you chnage value of Session variable it will be reflected in ur labelMAKMark as Answer if this reply helps youMVP ASP/ASP.NetASP.Net Hosting : Host DepotMy Site : ASPSnippets Thanks for you help but what I mean is there a method to add a control to form2 permenantly so even after i close the browser and re-open it the added control is still there . thanks. MinaSamy: Thanks for you help but what I mean is there a method to add a control to form2 permen...

Getting the Selected Item of dropdownlist inside Web User Control on a Web Form
Ive got a dropdownlist control inside a web user control called Entity.ascx. This web user control is on a webform.aspx. In Entity.ascx class I created a SelectedEntity property that returns the selected item in the dropdownlist. Inside webform.aspx when btnGo is pushed I set a string and pass it in the url. I am trying to get the entity they selected via the property (SelectedEntity) inside Entity.ascx. As the SelectedEntity property tries to return the selected item in the dropdownlist I get this error: System.NullReferenceException: Object reference not set to an instance...

Custom web control. Get Textbox.text value
Hi I have created a custom web control that extends the CheckBoxList control. It basically is a CheckBoxList control that has a TextBox added to the end of each CheckBox. It looks like the following after it has being bound to a database table column. I need to be able to retrieve the values in the corresponding TextBox when a CheckBox is selected. I tried storing each TextBox in an ArrayList but it is always empty when I try and check it. I am pretty new to ASP and am obviously missing something. Has anybody here got any tips or ideas on how I could retrieve the data from the TextBoxes...

C#.NET WEB APPLICATION
hei guys, i need help on my application, i'm using C#.NET as front-ed and SQL as back-end, aside from a datagrid, i want to display my data using textboxes and not a datagrid, i can do it using Visual Basic 6 but since i'm a newbee at C#.NET i don't know how to do it, specially the codes, can anyone help me with it? thank you in advance! If you are doing windows development, i would suggest using 'DataForm wizard' (Use Solution Explorer-->Rightclick project-->Add new Item-->New DataForm). It will guide you through steps. If you are doing web apps. Use quickstart to learn them. h...

Web control in web control
Hi,There are two simple web user controls A and B, where B contains A. They just display the bunch of text boxes, so I do not need them even in tool pane. They sit in the same project next to web form.I noticed that web user control put on ASPX page does not appear in code behind, but if I create it with protected keyword and name being exactly the same as id it works fine. I can access such a web control from code behind and see the value assigned in IE. The problem is that the same routine does work for my A web control in B. When I assign the value IE, I keep getting null reference. ...

Passing values from a parent web control to child web control
I have a parent control which called CONTROL1 and a child control witch called CONTROL2 I would link to pass a value from the parent control to the child control. In the parent control(CONTROL1) I have the following Event Handler . private void btn_Handler(object sender, EventArgs e) { …      if (Page.IsPostBack) {              // Send the officer names to the child controls.             if(m_nameList.SelectedItem.Text != "")     ...

getting values from a web form to windows form
Hot Requirement ..... Is there any possible of getting values from a web form to windows form ????? Yes One way i to use the WebRequest and WebResponse classes of the System.Net namespace. For example:  WebRequest request = WebRequest.Create("URL of the web page); WebResponse response = request.GetResponse(); StreamReader reader = new StreamReader(response.GetResponseStream()); string content = reader.ReadLine(); ....    Reza Nassabehwww.professionalcsharp.comDon't forget to click "Mark as Answer" on the post that helped you. That way fut...

How can I get the textbox value from a web user control inside an iframe?
Hi there, I have a page p1.aspx which has an iframe, if1, and a button sb1. The source of if1 is p2.aspx which has a web user control uc.ascx. In uc.ascx, there is a textbox, tb1, for user to enter a string. My question is: Is it possible to get the text of tb1 of uc.ascx in the p1.aspx when I click the button sb1? And How? Thanks in advance....

Can you return .net web controls in a .net page from a web service?
I've got a problem with a project. I've got to compile an entire .net page and return it as part of a Web Service for display. The problem I have is that I need to add WebControls and functionality to the page so that not only the html content and images are displayed (which I've managed) but that textboxes, labels, buttons and datasets can be displayed also. Essentially I need to make a call from one site for a page, populate the page and return it in a state as though it resided on the same server/webspace as the calling page. Code is currently built as follows into a string: strOpenHT...

Web Form and Web User Control
Hello, I have a Web User Control (ascx) that includes a button. This button has an onclick event method. This Web User control is included into a Web Form. (thru LoadControl). However, when I click on the button, the event method is not executed. What should I include in order it works fine? Thanks in advance. GAA. Using Loadcontrol is using dynamic controls and when using dynamic controls you must recreate the same dynamic controls ono postback to econstruct the page control tree. It is best if you do this during the Page PreInit event. How complex are your controls ...

Web part through web control -- how to get the url
I am not able to get the request variable to work in my webcontrol webpart.    Anybody know how i can get request or response to work? Hi, I’m not quite clear on your words. You mentioned in a WebPart project, you can’t get the request url variable?  But I think we can get it from Context.Request.Url , even in your WebPart application, web controls which be wrapped as a genericWebPart, i.e. you can assign the text property of a textbox webpart with the value you got from Context.Request.Url.  Anything wrong? Maybe I’ve misunderstood your words, if so, please feel...

Web User Control Not rendering in Web Form
I have created a Web User control that is made up of a Multiview with 2 views inside the Multiview. I have buttons on both views and a gridview on 1 view. My question is when I drop this Web User Control on a Web Form all I see is [MultiView"MultiView1"] and when I view the from in the browser I dont see the Web User Control. I was wondering if someone could please tell me why the Web User Control is not displaying or rendering.     Thanks In Advance Hi, Please check your aspx file for correct reference, like following example: TestControl.ascx:<%@ Control ...

custom web user control and web form
Guys,          I am trying to develop a context menu control for all of my pages. what i am trying to do is that i want the control to pick a datasource from the markup and then check whether its an xml file or a datatable. I created a class called datasource.   /**************************DataSource Class****************************/  public class DataSource { /// <summary> /// This is to identify unique elements from the markup /// </summary>protected string _ID; /// <summary> /// This will be the Datasource ID e...

How to Make Web Forms from other Web Forms
In putting together an ASP.NET application for a biz application, we have come to the point where there are three different types of basic forms which have, for the most part, been perfected. Now its is a matter of cloning those forms for various uses and modifying or adding code to suit the particular need. Copy and paste works OK, but there is a lot of changing of certain words, etc. Is there a way in ASP.NET to take these basic forms, turn them into classes or templates, create forms from them, then add or overwrite code? ? (Anybody who is a Vis Fox Pro programmer would know imme...

Web resources about - Cannot get value from an input textbox to a listbox web control?? - asp.net.web-forms

Control - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

How-To: Easily move items to full screen apps with Mission Control
Mission Control is a great feature found in OS X that can simplify the process of moving items between full screen apps when combined with Hot ...

Disable Windows 10's Microsoft Consumer Experience to take control of your Start menu
... used to add links to more third party apps in future. Here's what you need to do to disable the Microsoft Consumer Experience and regain control ...

The Oscars had the lowest ratings in years, and ABC is trying to get control to revamp them
After Sunday’s Oscars brought in the lowest ratings in eight years , the top brass at ABC is ready to have more control. The network — which ...

FDA strengthens warning on birth control implant
"Black box" warning will be placed on the Essure implant, but some women say that doesn't go far enough

In control: How to harness the power of your emotions – and play each of your 34,000 emotional states ...
Scientists have known for years that emotions impair our decision-making ability.

High-flying hack: Researcher shows how to seize control of a drone
German grad student Nils Rodday figured out how to intercept flight instructions and start flying a drone himself. He says the hardware he exploited ...

Limbaugh: Trump Is ‘Only Possibility Of Wresting Control Of The Country Back From The Upper Class’
Limbaugh: Trump Is ‘Only Possibility Of Wresting Control Of The Country Back From The Upper Class’

Star Fox Zero's motion controls can't be fully disabled
IGN reports that, despite earlier claims , motion controls can't be fully disabled for Star Fox Zero . Nintendo issued a statement explaining ...

Epic Games: Microsoft can't be allowed to control PC gaming
Tim Sweeney, co-founder of Epic Games (Unreal Engine, Gears of War), has written a scathing op-ed about Microsoft's Universal Windows Platform ...

Resources last updated: 3/4/2016 11:36:41 AM