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>";
                }
4

3 回答 3

1

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

var cityName = document.getElementById("cityName");
于 2013-05-04T08:48:58.397 回答
0

您可以创建一个 Session 变量来存储上传的文件内容并在另一个页面上访问它。

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

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

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 文本。

于 2013-05-04T08:40:16.290 回答
0

Telerik 特定的 API 可以帮助您将数据从 RadWindow 传递到父窗口,并且您可以使用 AjaxManager 重新加载上传的文件内容。

考虑这个演示如何将值从 RadWindow 传递回拥有页面的示例: http ://demos.telerik.com/aspnet-ajax/window/examples/clientsideevents/defaultcs.aspx?product=window

于 2013-05-06T13:26:55.013 回答