从后面的asp.net代码中检索HtmlSelect选项值 [英] Retrieve HtmlSelect option values from asp.net code behind

查看:70
本文介绍了从后面的asp.net代码中检索HtmlSelect选项值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在ASP.Net WebForm应用程序中有一个HTML选择控件。它的选项值是从客户端的jquery添加的。我希望在页面回发时从服务器端读取这些值。我有以下代码,但它不起作用。从客户端添加的选项值在后面的代码中不可用。我怎样才能将这些值提供给后面的代码?



//客户代码

I have a HTML select control in ASP.Net WebForm application. Its option values are added from jquery in client side. I would like to read those values from server side when the page is posted back. I have the following code, but it does not work. Option values added from client side are not available in code behind. How can i make those values available to code behind?

//Client code

<select title="Select one" id="selectBooks" multiple="multiple">
     <option value="1">test</option> //added in client side.
<select>





//代码落后



//Code behind

System.Web.UI.HtmlControls.HtmlSelect books= (System.Web.UI.HtmlControls.HtmlSelect)form1.FindControl("selectBooks");
foreach (ListItem item in books.Items)
{
   string test = item.Text.ToString();
}

推荐答案

你好,



FindControl 仅在您尝试查找服务器控件(具有属性 runat =server)并且您的选择是 HTML 控件。



您可以从访问它使用和不使用 FindControl 的服务器端,如果你向它添加 runat =server属性。





希望有帮助



Azee ......
Hello there,

FindControl only works if you are trying to find a Server Control (a control with attribute runat="server") and your select is an HTML control.

You can access it from the Server Side with and without using FindControl, if you add a runat="server" attribute to it.


Hope it helps

Azee...


我认为你需要使用RegsiterStartupScript来调用javascript函数表单服务器端。

这样你可以使用。



I think you need to use RegsiterStartupScript to call javascript function form server side.
Like this you can use.

ClientScript.RegisterStartupScript(GetType(),"id","callMyJSFunction()",true);





-SG



-SG


这篇关于从后面的asp.net代码中检索HtmlSelect选项值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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