2013-05-04 138 views
2

我使用的是asp.net c#和Telerik工具。我的问题是,我打算通过使用java脚本将(文本框,下拉列表和文件上传的详细信息)的值传递值+上传文件

传递到另一个asp页面,但没有任何工作,我想获取文件内容并将其作为好 ??你能给我一个解决方案吗?请!

在第1页:

<script type="text/javascript"> 
       function GetRadWindow() { 
        var oWindow = null; 
        if (window.radWindow) oWindow = window.radWindow; 
        else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow; 
        return oWindow; 
       } 
       function populateCityName(arg) { 
        var cityName = document.getElementById("cityName"); 
        cityName.value = arg; 
       } 
       function returnToParent() { 
        //create the argument that will be returned to the parent page 
        var oArg = new Object(); 

        //get the city's name   
        oArg.cityName = document.getElementById("cityName").value; 
        //get a reference to the current RadWindow 
        var oWnd = GetRadWindow(); 




        //Close the RadWindow and send the argument to the parent page 
        if (oArg.cityName) { 
         oWnd.close(oArg); 
        } 
        else { 
         alert("Please fill field"); 
        } 
       } 
      </script> 

第2页:

function OnClientClose(oWnd, args) { 
       //get the transferred arguments 
       var arg = args.get_argument(); 
       if (arg) { 
        var cityName = arg.cityName; 

      $get("order").innerHTML = "You chose to fly to <strong>" + cityName + "</strong>"; 
       } 
+1

什么都不行?你有什么尝试? – Sayse 2013-05-04 08:38:53

+0

首先,我尝试通过如下所示的文本框值,但我faild var cityName = document.getElementById(“cityName”); cityName.value = arg; – user2349354 2013-05-04 08:40:54

+0

另外我试图获取文件内容作为字符串来保存它的数据库,但我不知道该怎么做? – user2349354 2013-05-04 08:44:05

回答

0

您可以创建一个会话变量来存储上传fileContent和访问另一页上。

对于像文本框或下拉列表的简单文本,您可以直接通过查询字符串发送它们。

创建一个像这样的会话变量。

page1.aspx.cs

Session["FileContent"] = FileUpload1.FileContent; 

和访问它像下面的另一页;

page2.aspx.cs

if(Session["FileContent"]!=null) 
{ 
    Stream fileData = (Stream)Session["FileContent"]; 

    StreamReader reader = new StreamReader(stream); 
    string imgData = reader.ReadToEnd(); 

    //save imgData to db 
} 

您不能访问其他网页通过JavaScript控制值。
如果您通过这样做document.getElementById("cityName")没有得到任何东西,那么这就是说,在这个页面上没有这种带有id的控件。

尝试使用queryString(或Session变量)传递TextBox文本。

+0

我正在使用telerik上传工具,所以[FileUpload1.FileContent;]它不会使用它 – user2349354 2013-05-04 08:46:25

+0

那么是什么? telerik工具必须提供更简单的方式来获取文件内容。答案旨在展示如何将选定的文件数据从一个页面传输到另一个页面。 – 2013-05-04 08:49:17

+0

我会尝试使用querystring ..并为telerik我会再次尝试该方法,多谢提前帮助 – user2349354 2013-05-04 09:26:07

1

尝试使用
var cityName = document.getElementById('<%= cityName.ClientID %>');而不是

var cityName = document.getElementById("cityName"); 
+0

我使用了这两种方法,但它不会工作 – user2349354 2013-05-04 09:23:49

+0

首先检查名称由于telerik工具为您的browswer中的选择检查元素在html中更改。然后使用id代码使用html代码 – Dolo 2013-05-04 09:38:13

+0

如何将javascript变量从一个页面传递到其他页面? – Dolo 2013-05-04 09:38:44