C#后台给js传值(字符串)只收到第一个字符,
C#后台给js传值(字符串)只收到第一个字符,求助!
第一个页面(后台默认):
第二个页面.即new0.aspx
后台:
这个所有的代码,然后问题是,第一个页面接收值的"txt_goodsname"只能取到第一个字符'r'.
就这样一个问题, 苦恼了一天...
------解决方案--------------------
document.getElementById("txt_goodsname").value = goodsName[0];
===>
document.getElementById("txt_goodsname").value = goodsName;
------解决方案--------------------
goodsName[0],取goodsName的第一个字符
------解决方案--------------------
------解决方案--------------------
第一个页面(后台默认):
- C# code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default4.aspx.cs" Inherits="Default4" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title>无标题页</title> <script type="text/javascript" language="javascript"> //用于弹出b页 function ShowDialogArg(url, width, height) { var sFeature = "dialogWidth:" + width + "px;dialogHeight:" + height + "px;resizable:no;scroll:yes;center:yes;help:no"; return window.showModalDialog(url, window, sFeature); } //获取b页回传得数据 function GetGoods() { var goodsName = ShowDialogArg('new0.aspx', 800, 600); if (goodsName != null) { document.getElementById("txt_goodsname").value = goodsName[0]; } } </script> </head> <body> <form id="form1" runat="server"> <div> <asp:textbox id="txt_goodsname" runat="server" ReadOnly="True" Width="217px"/> <input id="Button1" onclick="javascript:GetGoods()" type="button" /> </div> </form> </body> </html>
第二个页面.即new0.aspx
- C# code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="new0.aspx.cs" Inherits="new0" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title>无标题页</title> <script type="text/javascript" language="javascript"> function getValue(aa){ var ss = new Array(); ss[0] = "eeeere"; window.returnValue = aa; //window.returnValue = ss; window.close(); } </script> </head> <body> <form id="form1" runat="server"> <div> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> </div> </form> </body> </html>
后台:
- C# code
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Data.SqlClient; using System.Configuration; public partial class new0 : System.Web.UI.Page { static string aa; protected void Page_Load(object sender, EventArgs e) { aa = "rwert"; Label1.Attributes.Add("ondblclick", "getValue('" + aa + "')"); } }
这个所有的代码,然后问题是,第一个页面接收值的"txt_goodsname"只能取到第一个字符'r'.
就这样一个问题, 苦恼了一天...
------解决方案--------------------
document.getElementById("txt_goodsname").value = goodsName[0];
===>
document.getElementById("txt_goodsname").value = goodsName;
------解决方案--------------------
goodsName[0],取goodsName的第一个字符
------解决方案--------------------
------解决方案--------------------