ASP Listrbox添加JavaScript但Items.Count = 0 [英] ASP Listrbox Adding JavaScript But Items.Count=0

查看:74
本文介绍了ASP Listrbox添加JavaScript但Items.Count = 0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

MY错误:Listbox1.ıtems.count= 0 :(



错误图片

http://i.hizliresim.com/lyy4NQ.png [ ^ ]



< b>JAVASCRİPT代码



Hello,
MY ERROR: Listbox1.ıtems.count = 0 :(

ERROR IMAGE
http://i.hizliresim.com/lyy4NQ.png[^]

JAVASCRİPT CODES

var opt = document.createElement("option");

   // Add an Option object to Drop Down/List Box
  document.getElementById("ListBox1").options.add(opt);
   // Assign text and value to Option object
  opt.text = file.path;
  opt.value = file.path;
  return true;





ASP.NET代码



ASP.NET CODES

<div>
   <h2 style="color:Navy">Galerideki Dosyalar</h2>
       <asp:ListBox  ID="ListBox1" runat="server"  BackColor="Teal"  ForeColor="Snow"   >
       </asp:ListBox>
       <br /><br />
      Seçilen Galeri Adresi:  <asp:Label  for="alan"  ID="alan"  runat="server" ForeColor="DarkGreen"  Font-Bold="true" >
       </asp:Label>

       <br /><br />
       <asp:Button Text="Galeriyi Ekle" ID="btneklegaleri" OnClick="btneklegaleri_Click" runat="server" />
   </div>





C#BUTTONCLİCK代码



C# BUTTON CLİCK CODES

for (int i = 0; i < ListBox1.Items.Count; i++)

{

    DataBase.Merkez.isINSERT("INSERT INTO GaleriPath (subid,imagepath) VALUES ('" + ListBox1.Items[i].ToString() + "','" + 1 + "')");

}

推荐答案

更改

change
document.getElementById("ListBox1").options.add(opt);



to


to

document.getElementById('<%=ListBox1.ClientID %>').options.add(opt);



如果您需要从后面的代码中获取项目,请使用


if you need to fetch items from code behind, use

string values = Request.Form[ListBox1.UniqueID];





参考:

添加(使用JavaScript和jQuery将项目插入ASP.Net ListBox [ ^ ]


.net控件不知道你添加的内容通过javascript。如果你想操纵客户端上的控件,那么使用标准的html元素而不是asp控件。另一种方法是将与您添加的项目相关的数据存储在隐藏字段中,并使.net代码从隐藏字段中读取新项目的数据。
.net controls don't know about things you've added via javascript. If you want to manipulate the control on the client then use standard html elements rather than asp controls. An alternative would be to store the data relating to the items you've added in a hidden field and have your .net code read the data for the new items from the hidden field.


这篇关于ASP Listrbox添加JavaScript但Items.Count = 0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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