网络编程
位置:首页>> 网络编程>> ASP.NET>> 在ASP.NET页面中如何利用JAVASCRIPT脚本向IFRAMES和POPUP传值

在ASP.NET页面中如何利用JAVASCRIPT脚本向IFRAMES和POPUP传值

 来源:codeproject.com 发布时间:2007-09-23 13:18:00 

标签:.net,iframe,popup

许多网页开发者想从ASP.NET 页面传递一个值到另一个页面(比如从一个框架frame页面到一个弹窗页面)。看了代码就明白了。呵呵。
(一)向IFRAME传值


// Client Script
function fnPostBackBetweenFrames(postBackFormString, frameName, actionUrl)
{
 var postBackForm = eval(postBackFormString);
 postBackForm.target = frameName;
 postBackForm.action = actionUrl;
 postBackForm.__VIEWSTATE.name = ’’;
 postBackForm.method = "post";
 postBackForm.submit();
 return false;
} // Server Code
string bottomFunction = String.Concat("javascript:return fnPostBackBetweenFrames(’document.", formName, "’,’bottomFrame’,’BottomForm.aspx’);");
btnPostFrame.Attributes.Add("onclick", bottomFunction);



上面是通过定义FROM表单之后。直接SUBMIT提交表单到指定的页面去。然后在后台通过

protected void Page_Load(object sender, System.EventArgs e)
        {
            txaValues.Text = GetParamValue("txaContent");
        }
protected string GetParamValue(string sKeys)
        {
            string request = String.Empty;
            
            if(Request.Params[sKeys] != null && Request.Params[sKeys].ToString() != String.Empty)
            {
                request = Request.Params[sKeys].ToString();
            }
            return request;
        }


就能得到另外一个页面IFRAME表单上的值
(二)弹出窗口赋值

// Client Script
function fnPostBackPopUp(postBackFormString, windowName, actionUrl, vWidth, vHeight)
{
 var postBackForm = eval(postBackFormString);
 var wForm = ViewCenterPop("about:blank", windowName, vWidth, vHeight, ’no’, ’no’, ’no’, ’no’, ’no’);
 postBackForm.target = windowName;
 postBackForm.action = actionUrl;
 postBackForm.__VIEWSTATE.name = ’’;
 postBackForm.method = "post";
 postBackForm.submit();
 wForm.focus();
 
 return false;
} // Server Code
string popupFunction = String.Concat("javascript:return fnPostBackPopUp(’document.", formName, "’,’PopPostBackWindow’,’PopupPage.aspx’,300,300);");
btnPostPopup.Attributes.Add("onclick", popupFunction); 


来源:http://www.codeproject.com/useritems/postwebformbetweenframes.asp

下载地址:postwebformbetweenframes.zip (15.62 KB)

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com