0

I have a jQuery variable like

Default.aspx:
  $(function () {
    $("#divimgbtnGo").click(function () {

       var ServiceNo = $(".ddlService option:selected").val();

    });
});

Here I am getting value into ServiceNo. I want to use these value in my codebehind (Default.aspx.cs).

Can anyone please help?

All information in search is about getting codebehind to aspx. SO could not found any useful result and stuck here

7
  • 3
    The drop down list box is send their selection to code behind with out do anything else. Now if you with so manipulate the serviceNo value and send it on code behind, you need to add it to some other hidden input control. Commented Apr 17, 2013 at 11:48
  • @Aristos SO never mentioned that ddlService is a server side control .. Commented Apr 17, 2013 at 11:52
  • @rahularyansharma Did not matter if its server side control, its looks that is a drop down list, so its send their selection to code behind anyway. Commented Apr 17, 2013 at 11:56
  • without runat="server" how you find value in c# ? Commented Apr 17, 2013 at 11:57
  • @rahularyansharma Using the Request.Form - check it out. Commented Apr 17, 2013 at 11:59

3 Answers 3

1

Have a hidden feild in your aspx page then pass your variable value to that hidden field like this

$(function () {
    $("#divimgbtnGo").click(function () {
        $("#<%= yourhiddenfield.ClientID %>").val($(".ddlService option:selected").val());
    });
});

In your Code behind get the value of hidden field as yourhiddenfield.Value

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

Comments

0

You can use, for example, a Hidden field, so ASP.NET will take care of transfering that data to the server and mapping it to CLR datatype after.

2 Comments

SO again do i need to assign these variable value to hidden filed and transer ??
@Pink: sure, you need to set the value into the field, so when the field is trasmited the valie of it can be read.
0

You can take hidden field and set ServiceNo value to hiddenField and u can use hiddenfield in server side. add hidden field in Default.aspx page <asp:HiddenField ID="hdnServiceNo" runat="server" />

set hidden field value.

$(function () {
$("#divimgbtnGo").click(function () {

   var ServiceNo = $(".ddlService option:selected").val();
   $('#hdnServiceNo').val(ServiceNo );
});

});

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.