Groups | Blog | Home
all groups > asp.net > january 2005 >

asp.net : Passing data to another aspx in different frame


Evan
1/8/2005 9:15:02 PM
I have a web page with 2 frames. The left frame is running menu.aspx and the
right frame is running images.aspx. When a selection is made in menu.aspx I
call a method in images.aspx and pass a variable. The intention is that
images.aspx will take the variable and load images into its frame (the right
one) based on the variable passed. What actually happens is the method runs
in the left frame and ruturns the error "Object reference not set to an
instance of a oblect" in the left frame. Nothing happens in the right frame.
The exception is pointing to the line of code located in images.aspx.cs.
How do I make the code in images.aspx.cs affect the frame it is in instead of
the frame it is called from?

Code in menu.aspx.cs:
private void Button1_Click(object sender, System.EventArgs e)
{
string tsource = Startup.MainSource[ListBox1.SelectedIndex].ToString();
string tlongdate = ListBox1.SelectedValue.ToString();
TextBox1.Text = tsource; //local to menu.aspx
Images gi = new Images();
gi.GetImages(tlongdate, tsource);
}

Code in images.aspx.cs:
public void GetImages(string LongDate, string Source)
{
Images mn = new Images();
//this text box is on images.aspx
mn.TextBox1.Text = LongDate; //here is the error
}

Thanks,
Steve C. Orr [MVP, MCSD]
1/9/2005 2:11:01 PM
You must understand that menu.aspx and images.aspx do not exist on the
server at the same instance in time, therefore they cannot communicate
directly with each other.
Instead you need to use other techniques, such as client side code and/or
Session state to pass data between the pages.
This is one reason I try to avoid frames with ASP.NET; it's usually too
complex to be worth it.
Instead it's generally a better idea to use User Controls to divide up
logical sections of your pages.

Here's more info:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbconintroductiontowebusercontrols.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vboriwebusercontrols.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbconWebUserControlsVsCustomWebControls.asp

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net


[quoted text, click to view]

Evan
1/9/2005 6:01:02 PM
That answers my question about my current behavior. The problem is that I am
converting an existing site to .NET and it uses two asp pages in separate
frames. Is there a way that a button click on menu.aspx can load images.aspx
in another frame? I can pass the data on the url line for the communication
between the pages. I was thinking maybe Response.Redirect but there is no
option for a target frame.

Thanks,
Evan

[quoted text, click to view]
Steve C. Orr [MVP, MCSD]
1/10/2005 1:55:06 PM
You're on the right track.
You can output a bit of client side javascript to do the trick.
Something like this should get you started:

Response.Write("<script language=javascript>parent.FRAMENAME.location
= 'whatever.aspx?MyParameter=4'</script>")

You could also use the RegisterClientScriptBlock or
RegisterStartupScript functions to do this.
Here's more info on these:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemWebUIPageClassRegisterClientScriptBlockTopic.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemWebUIPageClassRegisterClientScriptBlockTopic

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net




[quoted text, click to view]

AddThis Social Bookmark Button