I'm working on a project and presently I'm doing a module that belongs to a posting article page. In this page we have a option to add keywords by using textbox and button.
I done this by using jquery to add textbox enter keyword to listbox successfully.
If a user wants to remove any specific keyword after adding it the to listbox the user can remove it by selecting that keyword in the listbox then a remove button appears. If the user click that remove button keyword removed from listbox.
Problem :
After adding keyword successfully to listbox by using jquery but i can't access that listbox items in C# Code behind
Asp.net Page Listbox:
<a id="arkyw" href="#/"><font color="#cc0000">Remove Keyword</font></a>
<span id="spKeyword" style="color:#e74c3c;"></span>
<asp:ListBox ID="listBoxKeywords" runat="server" CssClass="list-group" style="border:0px; overflow-y:hidden; height:83px; width:300px;">
JQuery :
var count = [];
var i = 0;
$("#btnAddKeyword").click(function () {
var txt = $("#txtkeyword").val();
$('[id$=listBoxKeywords]').show();
if (jQuery.inArray(txt, count) != "-1") {
$("#spKeyword").text('Keyword alread exists');
} else {
var listCount = $('[id$=listBoxKeywords] option').length;
if (listCount <= 4) {
count[listCount] = txt;
var alreadyExist = false;
$('[id$=listBoxKeywords] option').each(function () {
if ($(this).val() == txt) {
$("#spKeyword").text('Keyword alread exists');
alreadyExist = true;
return;
}
});
if (!alreadyExist) {
$('[id$=listBoxKeywords]').append($('<option></option>').attr('value', count[listCount]).text(txt));
}
} else {
$("#spKeyword").text('5 Keyword limit exceed');
}
}
});
//Remove Value from the List
$('[id$=listBoxKeywords]').click(function (e) {
var $target = $(e.target);
if ($target.is('option')) {
$("#arkyw").show();
}
});
$("#arkyw").click(function () {
var a = $('[id$=listBoxKeywords] option:selected').val();
var id = $('[id$=listBoxKeywords] option').length;
//alert('ListCount : ' + a);
//alert('Total List Item : ' + id);
//alert('After Remove : ' + count[a-1]);
count = jQuery.grep(count, function (e) {
$('[id$=listBoxKeywords] option:selected').remove();
return e != a;
});
});
how to access listbox items in C# Code behind
Aucun commentaire:
Enregistrer un commentaire