Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a page that's written using ASP.Net (C#)
I have a button that is NOT a server control but is just an anchor (
HTML
<a href="java<!-- no -->script:Add_Button_Click">Add</a>
).
The menu code looks like this:
HTML
<ul>
<li><a href="java<!-- no -->script:Add_Button_Click('someString');">Add Value To ASP.Net ListBox</a></li>
</ul>


The "Add_Button_Click" (JavaScript):

HTML
<script type="text/javascript">
function Add_Button_Click(someStringValue) {

}
</script>


The "Add_Button_Click" (C# Code Behind):

C#
public static void Add_Button_Click(string someValue)
{
    ListBox box = Page.FindControl("ListBox1") as ListBox;//I'm not too sure if this part works but it's what I have so far.
}


In my page's Code Behind I need to be able to do two things:
1.) Call a C# function from the JavaScript code.
2.) In the C# function that's being called from JavaScript I need to add a ListBoxItem to an ASP.Net ListBox Server Control that resides on my page.

I've searched the web but can't seem to find a way to make any of these things work correctly.

Please show/tell me with example code how you guys would go about doing this, Thanks!!!
Posted
Comments
ChauhanAjay 19-Aug-14 0:40am    
Please check the below link it is a similar kind of question asked.
http://stackoverflow.com/questions/16307245/adding-an-item-to-a-listbox-using-javascript-works-on-windows-7-but-doesnt-work

1 solution

 
Share this answer
 
Comments
shelby67 19-Aug-14 2:50am    
I need to send a variable from javascript to the c# code behind now.
After that take that value and apply to listbox. This only does it in Javascript and I need to use the code behind

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900