-2

In the below code i have a static method inside static method i want to get the dropdown selected value.Pls help me to do this.

[WebMethod]
public static void InsertData()
{

}     

<asp:DropDownList ID="divlocation" runat="server" style="width:40%;" EnableViewState="true"/>
dario
  • 5,149
  • 12
  • 28
  • 32
  • 2
    You can't just "get" it, it doesn't exist in that context. You need to pass the value to the web webmethod using an ajax call from the browser. – Ben Robinson Dec 16 '14 at 12:32
  • @Ben Robinson I have tried with ajax i can able to send the value but how to get id? – Moses Vickson Dec 16 '14 at 12:34
  • Look at following link answering same question you post. http://stackoverflow.com/questions/24484765/how-to-access-dropdownlist-in-static-method – Abdul Rehman Dec 16 '14 at 12:59

1 Answers1

1

Here is an example of ajax

$.ajax({
            type: "POST",
            contentType: "application/json; charset=utf-8",
            url: "Pagename.aspx/webmethodname",
            data: JSON.stringify({ dropdownvalue: $('select[id$=divlocation]').val()}),
            dataType: "json",
            async: false,
            success: function (data) {
                alert("success");

            },
            error: function (err) {
                alert(err.responseText);
            }

        });

And in webmethod you will receive this value like this

[WebMethod]
    public static void InsertData(string dropdownvalue)
    {


    }
Mairaj Ahmad
  • 14,434
  • 2
  • 26
  • 40