1

I am pulling out my hair on this one for far too long now. Hopefully you guys can help out.

I have a form that allows a user to add "My Personal Skills" from the "Skills" list.

enter image description here

I have done the "Plus button (+)" and Minus button (-) code using the jQuery as below:

<script language="javascript" type="text/javascript">
function AddItSkills() {
    var selectedOptions = jQuery('#<%=ListITProgramming.ClientID %> option:selected');
    if (selectedOptions.length == 0) {
        alert("Please select option to move.");
        return false;
    }

    if (selectedOptions.length == 1) {
        if (jQuery("#<%=ListMyITProgramming.ClientID %> option[value='" + selectedOptions.val() + "']").length > 0) {
        }
        else {
            jQuery('#<%=ListMyITProgramming.ClientID %>').append(jQuery(selectedOptions).clone());
        }
    }
    else if (selectedOptions.length > 1) { jQuery(selectedOptions).each(function () { if (jQuery("#<%=ListMyITProgramming.ClientID %> option[value='" + this.value + "']").length > 0) { } else { jQuery('#<%=ListMyITProgramming.ClientID %>').append(jQuery(this).clone()); } }); }
    jQuery(selectedOptions).remove();
    return false;
}
function RemoveITSkills() {
    var selectedOptions = jQuery('#<%=ListMyITProgramming.ClientID %> option:selected');
    if (selectedOptions.length == 0) {
        alert("Please select option to move.");
        return false;
    }

    if (selectedOptions.length == 1) {
        if (jQuery("#<%=ListITProgramming.ClientID %> option[value='" + selectedOptions.val() + "']").length > 0) {
        }
        else {
            jQuery('#<%=ListITProgramming.ClientID %>').append(jQuery(selectedOptions).clone());
        }
    }
    else if (selectedOptions.length > 1) { jQuery(selectedOptions).each(function () { if (jQuery("#<%=ListITProgramming.ClientID %> option[value='" + this.value + "']").length > 0) { } else { jQuery('#<%=ListITProgramming.ClientID %>').append(jQuery(this).clone()); } }); }
    jQuery(selectedOptions).remove();
    return false;
}

In this scenario, "Skills" are bounded from the database and "My Personal Skills" are empty. The user adds the "Skills" into "My Personal Skills" and click on the Save button.

In c# code behind, I'm not able to get items list from "My Personal Skills" because they are added via jQuery.

Can you anyone give me the guidance to get "My Personal Skills" items in c# code behind?

4
  • use Request.Params["ListITProgramming"] Commented Jun 25, 2013 at 12:02
  • 1
    The easiest thing is to forget using jQuery, and put your ASP.Net controls in an UpdatePanel. Commented Jun 25, 2013 at 12:02
  • @Anna.P: I'm looking into what you have suggested. Commented Jun 25, 2013 at 12:04
  • @Daniel Gimenez: I have already done the solution using ASP.Net List box controls inside update panel but it is taking 2-3 seconds while moving values between two List boxes. And to increase the usability I'm trying to achieve it through jQuery. Any further suggestions? Commented Jun 25, 2013 at 12:08

1 Answer 1

1

Hidden fields will be the silver bullets here.

step1. add a asp hiddenfield to your page lets say hf1 is its id.

step2. add a clientclick event to your save button

step3.in the client clickevent get all personal skill and make them into a single string using comma or '|'

step4. set the hf1 value to the string generated by step3 and then post it.

step 5.On the server side get the value of the hf1 which will be the same string generated in 3rd step.

step6. deserialize it and //do any thing you want.

hope this help

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

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.