5,693,062 members and growing! (15,812 online)
Email Password   helpLost your password?
Web Development » ASP.NET » General     Intermediate

Post an ASP.NET WebForm with JavaScript between frames or into popup page

By JamesQ

This article demonstrate how to post an ASP.NET WebForm between frames or into popup page using javascript.
C#, HTMLWindows, .NET, .NET 1.1, Win2K, WinXP, Win2003, ASP.NET, Visual Studio, WebForms, IE 6.0, IE, Dev

Posted: 30 Mar 2006
Updated: 30 Mar 2006
Views: 25,434
Bookmarked: 27 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
8 votes for this Article.
Popularity: 3.68 Rating: 4.07 out of 5
0 votes, 0.0%
1
1 vote, 12.5%
2
1 vote, 12.5%
3
2 votes, 25.0%
4
4 votes, 50.0%
5
Note: This is an unedited contribution. If this article is inappropriate, needs attention or copies someone else's work without reference then please Report This Article

Sample Image - postbetweenFrames.jpg

Introduction

First, read "Post an ASP.NET form with JavaScript" By David Truxall before your read this article! It can understand for most develpers to have difficulty in using an ASP.NET postback process in .NET 1.x. In addition to David's article, This article describes how to post between frames or into popup, with a flexible javascript.

Background

The most web developers would think of posting a ASP.NET WebForm to another WebForm page(that is, through frame or into popup WebForm). In an enterprise web solution, we sometimes use framesets. I know that using framesets makes the performance worse. But if our customer want to use the framesets, what I have to do?

Using the code

I have a frameset which is horizontally divided into two frames. One has a frame name called "topFrame", the other "bottomFrame". When I input some text into TextBox and click a "Post to Bottom Frame" button on "topFrame", it posts the "bottomFrame" page. Additionally, When I click a "Post to Popup" button on "topFrame", it posts the Pop-up Page("PopupPage.aspx").

   - Description of script function :

  • fnPostBackBetweenFrames(postBackFormString, frameName, actionUrl)
    : Post between frames
  • fnPostBackBetweenPages(postBackFormString, actionUrl)
    : Post between pages
  • fnPostBackPopUp(postBackFormString, windowName, actionUrl, vWidth, vHeight)
    : Post into popup page

// 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);

The fnPostBackBetweenFrames script function is used to post between frames and the server code(of behind class) is showing the code registering the onclick event function of "btnPostFrame" button.

// Client Script

function fnPostBackBetweenPages(postBackFormString, actionUrl)
{
 var postBackForm = eval(postBackFormString);
 // Without a target property, a page will be posted from current page to "actionUrl" page.

 postBackForm.action = actionUrl;
 // if you want to pass the "__VIEWSTATE" value to other page, give your favorite name to a name property.

 postBackForm.__VIEWSTATE.name = '';
 postBackForm.method = "post";
 postBackForm.submit();
 return false;
}

The fnPostBackBetweenPages script function is used to post between pages. this script is similar to the fn PostBackBetweenFrames function.

// 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);

The fnPostBackPopUp script function is used to post into popup page and the server code(of behind class) is showing the code registering the onclick event function of "btnPostPopup" button.

private void Page_Load(object sender, System.EventArgs e)
{
  txaValues.Text = GetParamValue("txaContent");
}

If the data is posted to another WebForm, just handle Request.Form key with the customized function "GetParamValue(string sKeys)" (from BasePage.cs)

Points of Interest

The key point of this feature is the rename of "__VIEWSTATE". In VS 2005, we have a Cross-Page feature but I don't know that it solved the previous post processing problem. Sooner or later I will test the Cross-Page feature with VS 2005 and if needed, I will write other client script in relation to the post processing.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

JamesQ



Occupation: Web Developer
Location: Korea, Republic Of Korea, Republic Of

Other popular ASP.NET articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 5 of 5 (Total in Forum: 5) (Refresh)FirstPrevNext
Questionwhat about vb.netmemberAtif Younas16:19 8 Mar '07  
Generalvalidatorsmemberfetty4107:25 17 Apr '06  
GeneralRe: validatorsmemberJamesQ15:34 17 Apr '06  
GeneralThanksmemberMircea Grelus11:46 12 Apr '06  
GeneralRe: ThanksmemberJamesQ15:38 17 Apr '06  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 30 Mar 2006
Editor:
Copyright 2006 by JamesQ
Everything else Copyright © CodeProject, 1999-2008
Web07 | Advertise on the Code Project