使用javascript函数从C#代码后面将ListBoxItem添加到ListBox [英] Add ListBoxItem to ListBox from C# code behind using a javascript function

查看:62
本文介绍了使用javascript函数从C#代码后面将ListBoxItem添加到ListBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用ASP.Net编写的页面(C#)

我有一个不是服务器控件但只是一个锚点的按钮(

 <   a     href   =  java<! -  no  - > script:Add_Button_Click > 添加<   / a  >  

)。

菜单代码如下所示:

< pre lang =HTML> < ul >
< li > ; < a href = java< ! - no - >脚本:Add_Button_Click('someString'); > 为ASP.Net ListBox添加值< / a > < / li >
< / ul >





Add_Button_Click(JavaScript):



 <   script    类型  =  text / javascript > ;  
function Add_Button_Click(someStringValue){

}
< / script >





Add_Button_Click(C#Code Behind):



  public   static   void  Add_Button_Click( string  someValue)
{
ListBox box = Page.FindControl( ListBox1 as ListBox; // 我不太确定这部分是否有效,但这是我到目前为止所做的。
}





在我的页面代码背后我需要做两件事:

1.)打电话给C#fu从JavaScript代码开始。

2.)在从JavaScript调用的C#函数中,我需要将一个ListBoxItem添加到驻留在我页面上的ASP.Net ListBox服务器控件中。



我在网上搜索过但似乎无法找到让这些东西正常工作的方法。



请用示例代码告诉我你们怎么做这个,谢谢!!!

解决方案

看看这个样本。



http: //www.c-sharpcorner.com/UploadFile/mahakgupta/add-and-remove-listbox-items-in-javascript/ [ ^ ]


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 (

<a href="java<!-- no -->script:Add_Button_Click">Add</a>

).
The menu code looks like this:

<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):

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

}
</script>



The "Add_Button_Click" (C# Code Behind):

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!!!

解决方案

Look on this sample.

http://www.c-sharpcorner.com/UploadFile/mahakgupta/add-and-remove-listbox-items-in-javascript/[^]


这篇关于使用javascript函数从C#代码后面将ListBoxItem添加到ListBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆