We help IT Professionals succeed at work.
Get Started

Curious how Expert Awards are earned? Find out on this week's podcast, featuring Experts Exchange CEO Randy Redberg.Listen Now

x
Troubleshooting Question

Populate ASP.Net TextBox with value from DropDownList using JQuery

87 Views
Last Modified: 2020-10-13
I am trying to populate a TextBox within an ASPX page (C#) with a dropdownlist value using JQuery. I have no idea if this is right. I'm simply trying things I am readying on the internet. The Javascript says that DDL_ID (which I assume would be the dropdowlist) and TextBoxID (which i assume is the textbox) CANT BE FOUND. I don't know if this will work or not but I am trying anything I can at this point to prevent users from having to type in a freeformtextbox.

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

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
 <script src="jquery-3.5.1.min.js"></script>
<script type="text/javascript">
    $('#<%= DDL_ID.ClientID %>').change(function() {
    $('#<%= TextBoxID.ClientID %>').val($(this).val());
});
</script>

</head>
<body>
    <form id="form1" runat="server">
        <div>form
        </div>
        <div>
            <asp:FormView ID="FormView1" runat="server" AllowPaging="True" DataKeyNames="id" DataSourceID="SqlDataSource1">
                <EditItemTemplate>
                    id:
                    <asp:Label ID="idLabel1" runat="server" Text='<%# Eval("id") %>' />
                    <br />
                    City:
                    <asp:TextBox ID="CityTextBox" runat="server" Text='<%# Bind("City") %>' />
                    <br />
                    Citycode:
                      <asp:DropDownList ID="DDL_ID" runat="server"   >
                        <asp:ListItem Value="0" Selected="True">Select</asp:ListItem>
                    </asp:DropDownList>
                    <asp:TextBox ID="TextBoxID" runat="server" Text='<%# Bind("Citycode") %>'/>
                    <br />
                    <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update" Text="Update" />
                    &nbsp;<asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
                </EditItemTemplate>
Comment
Watch Question
CERTIFIED EXPERT
Distinguished Expert 2020
Commented:
This problem has been solved!
Unlock 1 Answer and 24 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant

An Experts Exchange subscription includes unlimited access to online courses.

Get Started
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE