By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,894 Members | 1,086 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,894 IT Pros & Developers. It's quick & easy.

Passing strings across webforms

P: n/a
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.
Nov 16 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a

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.
"Newbie" <Ne****@discussions.microsoft.com> wrote in message
news:9B**********************************@microsof t.com...
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.

Nov 16 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.