Selecting a Value in a Drop Down List Based on the Value of a Textbox

I have a formview control (.NET 2.0/VS2005) in which users enter company contact information.  When a user enters a postal code in the appropriate text box, the territory for that company needs to be calculated and displayed in a territory drop down list.

I know how to calculate and retrieve the territory from my SQL Server database, but I can't seem to nail down how to trigger the code and don't want the user to have to click a button.

I tried using the OnTextChanged event, but that doesn't seem to be what I want because I need this calculation to be performed prior to saving the record.

Can anyone point me in the right direction?

Thanks in advance!

Lori 

0
Aradia926
4/4/2006 7:21:47 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

2 Replies
778 Views

Similar Articles

[PageSpeed] 19

Ok, so I've been doing some research and determined that since I'm using asp.net 2.0, a client callback should work.

That's about all I've figured out.

I've been trying to piece something together from various tutorials, examples etc. from all over the web, but I'm not having much luck.  This is mostly because I don't know much about javascript.  

I'm desperately trying to learn, and trust me I've been googling furiously and reading everything I can get my hands on (I've always thought that people who don't try to help themselves first really don't deserve the help of others) but I just don't know where to go from here.    

This is what I have (mostly taken from http://www.asp.net/QuickStart/aspnet/doc/tipstricks/default.aspx#clientscriptgoodies):

Dim _callBackResult As String

In Page_Load:

Dim callBack As String = Page.ClientScript.GetCallbackEventReference(Me, "arg", "ClientCallback", "context", "ClientCallbackError", False)
             Dim clientFunction As String = "function GetChildren(arg, context){ " & callBack & "; }"
             Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), "GetChildren", clientFunction, True)


             If Page.IsPostBack AndAlso Not Page.IsCallback Then
                 Dim territory As DropDownList
                 territory = CType(Me.DetailGrid.FindControl("ddlterritory"), DropDownList)
                 If _callBackResult <> "" Then
                     territory.SelectedValue = _callBackResult
                     end if
                 End If

Public Function GetCallbackResult() As String Implements System.Web.UI.ICallbackEventHandler.GetCallbackResult
             Return _callBackResult
         End Function

         
         Public Sub RaiseCallbackEvent(ByVal eventArgument As String) Implements System.Web.UI.ICallbackEventHandler.RaiseCallbackEvent

             
             'Here I get the territoryID for the Company and store it in a variable of the same name
             
             _callBackResult = territoryID
             
         End Sub

In <script> portion of my contentplaceholder:

function ClientCallback(result, context){

      'Not really sure what goes here, obviously that is a BIG problem!

   }

   function ClientCallbackError(result, context){
      alert(result);
   }

Can anyone explain to me what I need to do to achieve the results I need??  Please help!

0
Aradia926
4/7/2006 8:45:39 PM

Aradia926:

I tried using the OnTextChanged event, but that doesn't seem to be what I want because I need this calculation to be performed prior to saving the record.

You are right in using the OnTextChanged event. TextChangedEvent will be fired when there was a change in the text and the focus was lost from the textbox. I am sure, you have only the code to get the territory in the ontextchanged event and not code for saving. Set the autopost back property of the textbox to true.

If you have a button set as default button, then when the user key in ENTER, on the textbox, the button click event will be fired. So, set the UseSubmitBehavior to false.

HTH


Mark post(s) as "Answer" that helped you

Electronic Screw
Website||Blog||Dub@i.net
0
e_screw
4/8/2006 8:37:48 AM
Reply:

Similar Artilces:

How to get the list of second drop-down-list based on value selected in the first drop-down-list
I have two drop-down-lists, the second one depends on the value chosen in the first drop-down-list.  In the first drop-down-list, I have AutoPostBack = "true" and OnSelectedIndexChanged = "SelectedIndexChanged" In the selectedIndexChanged method, I do the following: 1    protected void SelectedIndexChanged(object sender, EventArgs e)2        {3            if (IsPostBack)4            {5      &nbs...

Drop down list control values OK but not showing selected value on UI
 Hi, I am having trouble with the following: ddlIndustry.Items.FindByText(oReader["industry"].ToString()).Selected = true;  I am trying to get the ddlIndustry drop down list to bind to a specific product industry got from a database like say "Agriculture". Even when i assign a hardwired and existent value like "Agriculture" as from the database,  the Selected value or text does change from initial option from the list with (this I verified in Debug mode) but when the page is generated, the Drop down list maintains value 0 and text "--select one --". Is there something i am...

Selected value in select list with javascript based off value in database
 I've got a classic asp page with a select list. I need the select list's selected value to be whatever the user selected when they created their account. I've been trying to use <body onLoad="onLoad();"> to call my function, and then I'm trying to specify which value should be selected in the function. Also, when the select list selected values change, there is a javascript function I call to disable text boxes. I think there is an issue with my javascript function, and I can't find any examples of this from good ole' google.  My j...

Populate 2nd drop-down list box based on selected values in 1st drop-down list box
Hi Group,I have two DDL boxes on my page.  DDL one has a list of values and a code.e.g code  ValueABC   123ABC   345FGH   123 DDL 2 should only show values for the code selected in  DDL1 e.g  if user selects record 1 with code ABCthen DDL2 should show ALL records with the linked field value of ABC.The tables are normalized.  For your info, the name of the field of the value I would like to check is called sublistcode.Using vb.net  TIA         Try this code: Note: Set appenddataboun...

Error Populating a textbox in the Gridview Item Template Row based on a drop down list selected value
Hello, I would like to Populate a textbox in the Gridview Item Template row based on a drop down list selected value.  Right now I have the basic gridview where I have to click on the edit butio to update each row.  To get around the single row edit, I decided to move the edit fields to the Item Template Row where the databound fields are in edit mode when the page opens so I can perform a bath update.  The only problem is that the ddlComp_SelectedIndexChanged works when the page is designed to edit the a single row at a time.  Since I move the fields to th...

Dropdownlist selected value passes first value in list no matter what value is selected. why ?
 HI . I have a dropdownlist. Databinds ok but when I must pass a value as a Selected value it always passes the first value in the list even if I select another value. I tried to set the ddl to enableviewstate false but it doesn't change anything. Any ideas ? Code below, thanksLoading the ddl:       productCategories = CatalogAdmin.Admin_Product_Categories_NotIn(productId);        for (int i = 0; i < productCategories.Rows.Count; i++)        {       &...

How to show value in textbox from selected value in Dropdown list
I have two text box, txtbox1 should be from two field for example i have one dropdownlist where i select item and another txtbox2 i want to put value, when i first time to write manually value in txtbox2 in and selected item from ddl i want to result in concatenate from in txtbox1. for example  I haveif not me.ispostback thenDim cm as new sqlcommand("Select AccMjrid, Names from Accgrp", me.sqlconnection1.open())me.sqldataAdapter1.fill(Dataset1, "Accgrp") Me.cmbAccMajID.DataSource = Me.DataSet11.Tables("AccMajor") Me.cmbAccMajID.DataTextField = "AccName" Me.cmbAccMajID.DataValueField ...

How to set selected value in drop down based on query value
i have a dropdownlist populated with values frm database   when i want to view or edit a particular record i populated the textbox with the needed record details same way i wan the dropdown to display the selected value as the first index received frm the query  If you palced it inside a data control , then you can bind it's selected value with a database field like this :<asp:DropDownList id=...  SelectedVale='<%# Eval("DataBaseField") %>'  .... Regards,Anas Ghanem.Note:Please Don't hesitate to click "Report Abuse" ...

Updating values of dropdown lists on a page based on a textbox value
Hi Everyone,  I know from the title this seems simple however there is a twist.  I have a page that a user fills out to submit feedback on products.  To keep data clean, I let them select the product, type and size based on dropdown lists, but also want to make it so if they type in the barcode, the values for the Product, Type and Size are looked up and populated on the form for them to see it before submitting the form. The form has several textboxes and dropdown lists that update using SQLDataSource connections.  The problem that I'm running ito is ...

Setting values based on drop down list selection
Hi Im developing a cinema booking system for a college project, I currently have a datagrid which holds each seat the user has selected. In the next column I have a drop down list which holds of the different customer types, when a button is selected i am able to loop throught the the grid retrieving all the information. However what im trying to do now is to add another column to the grid which would hold the cost of the seat (cost being based on screen no held on a session variable and the currently selected customer type). When the page is loaded there is always the same customer...

Displaying values from 3 textboxes automatically after selecting a value from a dropdown list
 The dropdown list is databind to a sqldatasource from the Bike Table.After selecting a bike Name from the dropdown list, the status and rent price will be displayed on the 2 textboxes automatically.Both the status and  rent price values are taken from the same Bike Table.Can anyone help me with this?Thanks. On the selected index change property of the dropdownlist hit the database to get the details (status and rent ) for the selected Item and set the values to the text of textboxes.Hope this helps. Just do this in your OnSelectedIndexChanged event of the ddlSqlCommand cmd =...

Drop Down List Populated Depending Upon the value Selected in another Drop Down List
  I have five drop down lists.Each One populated based on the value selected in the previious one. I have used SqlDataSource for binding data to each drop down.And I need some initial value so I put "AppendDataBoundItems" as true.Functionality is ok. The problem is, I have selected one from first dropdown.then second drop down is populated.but now i want to select a different value from first dropdown.If i do so,To my second drop down list the values r being appended.not refreshed.I think this is because AppendDataBoundItems=true Plz suggest me something. Thanks in Advan...

I want to display textbox on changing value of dropdownlist or selected value of dropdown list.How could i?
for example i have taken field PF%,PF($)  in dropdown.Onselected value of % i will show textbox.In which u can fill  the value of PF% based on that calulation will be shown in other textbox. But how can i do thta? Not too sure I undertand your question, but if you want to show/hide elements here's a few things you might want to try: You can set the dropdown's autopostback to true and perform all sorts of wonderful serverside stuff, including adding a textbox control (with a certain value) to a container div. If you want to keep things light then use some CSS and ...

Update 2 drop-down list based on values of the 1 drop-down list box
 Hi,I am using ASP.NET,C# and SQL ServerI have 2 Drop down list boxes.In first List box I have: countries ...I need to Update 2 text box with corresponding states...I am getting these values from database both country and states... How to implement this ..can anyone help me on this...Please provide some code examples ...It will be helpful... Did you checked Ajax CascadingDropDown ?  My Blog"Don't be afraid to be wrong; otherwise you'll never be right." Create a Sub to handle the SelectedIndexChanged of your Country drop down.  Anytime the country i...

Web resources about - Selecting a Value in a Drop Down List Based on the Value of a Textbox - asp.net.presentation-controls

Consultation Document on the Methods for Selecting the Chief Executive and for Forming the LegCo in 2012 ...
The " Consultation Document on the Methods for Selecting the Chief Executive and for Forming the LegCo in 2012 " was a document published on ...

Voting Machine Caught on Camera Casting Ballot for Democrat when Selecting Republican - YouTube
**UPDATE.... I've heard many reports that this is "just a calibration issue." I will say this... when I went to page 2 and began voting for city ...

Selecting decor that will move with the times
What colours should I use in my home so that my d&#233;cor is neutral and flexible but not boring?

Clock ticking on selecting successor to Leigh Clifford at Qantas
With Qantas on course to chalk up its largest annual profit since 2008, the question now is whether chairman Leigh Clifford is looking to hang ...

Why are the reserves selecting the team?
Backbenchers are the reserves of the parliamentary system. They are newcomers.

Jackie French: Why selecting the right place for your plants is important
The secret of growing anything easily is to choose the best spot for what you want to grow.

Netflix turns to pirates when selecting new shows
Imagine the surprise, then, when the popular video streaming site admitted that it actually turns to torrenters for inspiration. "With the purchase ...

Boston Marathon bombing trial: Judge, lawyers face challenges in selecting jurors - CTV News
As the second phase of jury selection began in the federal death penalty trial of Boston Marathon bombing suspect Dzhokhar Tsarnaev, it immediately ...

Selecting cabinet one of first orders of business for Trudeau
One of the first orders of business for any new prime minister is picking a cabinet. Who is likely to make the cut?

Agile Analysis, Self-Selecting Teams, TDD & BDD in Methods & Tools Winter 2014 issue
... for software developers, testers and project managers – has just published its Winter 2014 issue that discusses Agile Analysis, Self-Selecting ...

Resources last updated: 11/26/2015 3:47:21 AM