Passing data to another aspx in different frame

G

Guest

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,
Evan R. Hicks
 
S

Steve C. Orr [MVP, MCSD]

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/d...n/html/vbconintroductiontowebusercontrols.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vboriwebusercontrols.asp
http://msdn.microsoft.com/library/d...l/vbconWebUserControlsVsCustomWebControls.asp
 
G

Guest

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

Steve C. Orr said:
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/d...n/html/vbconintroductiontowebusercontrols.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vboriwebusercontrols.asp
http://msdn.microsoft.com/library/d...l/vbconWebUserControlsVsCustomWebControls.asp

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


Evan said:
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,
Evan R. Hicks
 
S

Steve C. Orr [MVP, MCSD]

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/d...UIPageClassRegisterClientScriptBlockTopic.asp
http://msdn.microsoft.com/library/d...mWebUIPageClassRegisterClientScriptBlockTopic

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




Evan said:
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

Steve C. Orr said:
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/d...n/html/vbconintroductiontowebusercontrols.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vboriwebusercontrols.asp
http://msdn.microsoft.com/library/d...l/vbconWebUserControlsVsCustomWebControls.asp

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


Evan said:
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,
Evan R. Hicks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top