Passing strings across webforms

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there a way to pass strings from one webform to another without using
Response.Redirect( ) ? The reason is that I need the webform passing the
string to close its window.
 
In this case, has the first window opened the second? You're then assigning
some value back to the opener window from the second window. Sort of
simulating the modal dialog situation in windows programming.

Say A opens window B...
Then in this case, then you need to:
- first pass the value from the B to A
- then refresh A from B
- before closing B


Request.QueryString
---------------------

If the string is short you can refresh A and pass in the information via a
query string i the URL using javascript.

(bForm.aspx.cs)
string dataString = "String to pass back";
StringBuilder scriptBuilder = new StringBuilder();
scriptBuilder.Append ( "<SCRIPT>" );
scriptBuilder.Append ( "windows.opener.location.href = 'aForm.aspx?data='" +
dataString + "'" );
scriptBuilder.Append ( "</SCRIPT>");
RegisterClientSideScript ( scriptBuilder.ToString() );

Then in the opener (aForm.aspx.cs) code, you can access this by calling
Request.QueryString["data"] in the Page_Load method.


Session object
---------------

Another way would be to replace the windows opener line with this:
(bForm.aspx.cs)
Session.Add ( "data", dataString )
....
// refresh the opener
scriptBuilder.Append ( "windows.opener.location.href =
windows.opener.location.href" );
....

then from aForm.aspx.cs in the Page_Load method, call
Session["data"] to get the data string back. Remember that if a session
object called data is found, it should probably be cleared in this case so
that each time the aForm reloads it doesn't think there's more data there.


If you're not opening windows using javascript script window.open then this
won't work, and the may problem is getting the second form to refresh the
first.

hope that helps.
Dan.
 
Back
Top