1

I need to get a value that I got in Javascript to my code behind file..

My design code is:

<asp:DropDownList ID="ddlStatusOverview" runat="server" Width="95px" onchange="CheckSelectedItem(this)" >

</asp:DropDownList>

I'm using the dropwonlist in "ItemTemplate" of asp:ListView.

My javascript coding is:

<script type="text/javascript">
function CheckSelectedItem(ddl) {
alert(ddl.value);
}

I want to get that "dll.value" value in code behind.. I already used Webmethod concept. But my problem is I need to get the value in ".ascx" page.. How to do that..?

I don't know how to use hidden field value concept too..

2
  • use server side methods, OnSelectedIndexChanged...and read values from arguments Commented Nov 25, 2013 at 10:50
  • I coudln't use the "OnSelectedIndexChanged" method as I'm using it inside a table.. Commented Nov 25, 2013 at 10:56

2 Answers 2

1

Do this :

Add a hidden field element :

<input name='lala' id='lala' type='hidden'/>

Add this :

function CheckSelectedItem(ddl) {
  document.getElementByID('lala').value=ddl.value;
}

On server side :

you can get the value by :

Request.Form["lala"].ToString();


Accoring to your comment :

If I want to call a server side function from javascript with this "ddl.value" means, how to do that?

Please read this

ASP.NET pass a javascript value in server side

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks.. If I want to call a server side function from javascript with this "ddl.value" means, how to do that?
0

Introduce a hidden field.

<script type="text/javascript">
    function CheckSelectedItem(ddl) {
        document.getElementByID('hfStatus').value = ddl.value;

        // if using jQuery
        // $("hfStatus").val(ddl.value);
    }
</script>

<asp:HiddenField runat="server" ID="hfStatus" />

Now you can directly access hfStatus from code-behind.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.