Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8933647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:35:38+00:00 2026-06-15T09:35:38+00:00

I have a textbox and a dropdownlist on my client side. I need to

  • 0

I have a textbox and a dropdownlist on my client side. I need to pass the values of these controls to a webmethod (in the code behind) using javascript.
I can pass the textbox value but not the dropdownlist.

<p><asp:DropDownList id="ddlList" runat="server"></asp:DropDownList></p>
<p><asp:TextBox ID="txtSearch" runat="server"  OnTextChanged="txtSearch_TextChanged"    OnKeyPress="onKeyFunction();" AutoPostBack="True"></asp:TextBox>
<asp:GridView ID="grdLista" runat="server"></asp:GridView>

<script type="text/javascript">
    function onKeyFunction() {
        var search = document.getElementById('<%=txtSearch.ClientID %>').value;
        //var ddl = i need to pass the dropdownlist values here..
        PageMethods.callJS(search, /*ddl */, onSucess, onError);

        function onSucess(result) {
            alert(result);
        }

        function onError(result) {
            alert('Something wrong.');
        }
    }
</script>

And this is the code in my WebMethod

[WebMethod]            
public static IEnumerable<string> callJS(string search)
{
    IEnumerable<string> results = itemList.Where(item => item.Contains(search.ToLower()));
    return (results);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T09:35:39+00:00Added an answer on June 15, 2026 at 9:35 am

    You can get the value of your DDL like this :

    var liste =  document.getElementById('#ddlList');
    var ddl = liste.options[liste.selectedIndex].value;
    

    EDIT :

    In order to retrieve all the values from a DDL, we have to loop over the options values:

    var ddl = [];
    for(var i = 0; i<3; i++) {
        ddl.push(document.getElementById("<%=ddlList.ClientID %>").options[i].value);
    }
    

    This array can be get at server side as a List<string>:

    [WebMethod()]
    public static IEnumerable<string> callJS(List<string> ddl) { ... }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to validate TextBox based on Value selected in DropDownList controls. I have
I have a gridview which contains controls like checkbox dropdownlist textbox etc.. These controls
I have: Textbox(Multi-line) Panel Different controls inside panel (buttons,textbox) Scenario: I need to add
I have code to append value from dropdownlist to the textbox. But I am
I have a serie of controls on each row (dropdownlist, textbox, button, ...). I
I have this code on an aspx page. <asp:DropDownList runat=server ID=ddlSize CssClass=textbox Width=100px> <asp:ListItem
I have a page that contains some dynamically created controls (TextBox and DropDownList). When
I have a dropdownlist and a textbox with a button on a form. When
I have got a dropdownlist, a submit button and a textbox in my view.
I have update panel that content check box, textbox, 3 DropDownList with CascadingDropDown extender.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.