Solved

redirect pages to another frame in ASP.NET

Posted on 2004-09-21
9
592 Views
Last Modified: 2012-08-13
Hi experts,

I know this question is common. How do I redirect pages to another frame in ASP.NET?
I have 3 frames; top, left and right. I wanna keep the top and the left the same and load new pages on the right frame.

Here's the frame code:

<html>
<head>
    <title>Banner and Content Frameset</title>
    <meta content="Microsoft Visual Studio.NET 7.0" name="GENERATOR" />
    <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema" />
</head>
<frameset border="0" framespacing="0" rows="111,81%" frameborder="0">
    <frame name="banner" src="Header.aspx" />
    <frameset border="0" framespacing="0" frameborder="0" cols="150,75%">
        <frame name="contents" src="contents.aspx" />
        <frame name="main" src="main.aspx" />
    </frameset>
</frameset>
</html>

Here's my Header.aspx code:

<%@ Page Language="VB" %>
<script runat="server">

    Sub page_Load
        if ( not ispostback )
            drpRestaurantName.Items.add ("Peking Taste")
            drpRestaurantName.Items.add ("Jade Garden")
        else
            if (drpRestaurantName.selectedIndex = 0 )
                Response.Redirect ("default.aspx")
            else
                Response.Redirect ( "http://www.pyrius.com" )
            end if
            'Response.Write("You just selected " & drpRestaurantName.selectedItem.Value )
        end if
    End Sub

</script>
<html>
<head>
</head>
<body>
    <form runat="server">
        <p>
            Choose Your Restaurant: &nbsp;<asp:DropDownList id="drpRestaurantName" runat="server" AutoPostBack="True"></asp:DropDownList>
        </p>
        <!-- Insert content here -->
    </form>
</body>
</html>

I want default.aspx to appear on the "contents" frame.

Any help will be greatly appreciated!

thanks.

TJ
0
Comment
Question by:protugy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
9 Comments
 
LVL 5

Expert Comment

by:ajitanand
ID: 12120627
response.Redirect is not the correct way to control client side navigation across frames. Rather use javascript as follows:

Sub page_Load
        if ( not ispostback )
            drpRestaurantName.Items.add ("Peking Taste")
            drpRestaurantName.Items.add ("Jade Garden")
        else
            if (drpRestaurantName.selectedIndex = 0 )
                Response.Write("<script language=""javascript"">window.open(""default.aspx"",""contents"");</script>")
            else
                Response.Write("<script language=""javascript"">window.open(""http://www.pyrius.com"",""contents"");</script>")
            end if
            'Response.Write("You just selected " & drpRestaurantName.selectedItem.Value )
        end if
End Sub

----------------------

rgds,
Ajit Anand
0
 

Author Comment

by:protugy
ID: 12126177
It doesn't work. It still redirects on the same frame.
Can we actually embed one language with another language?

thanks.

TJ
0
 
LVL 5

Expert Comment

by:ajitanand
ID: 12130460
Wait. You have the frameset as:
<frameset border="0" framespacing="0" rows="111,81%" frameborder="0">
    <frame name="banner" src="Header.aspx" />
    <frameset border="0" framespacing="0" frameborder="0" cols="150,75%">
        <frame name="contents" src="contents.aspx" />
        <frame name="main" src="main.aspx" />
    </frameset>
</frameset>

And you say "I have 3 frames; top, left and right. I wanna keep the top and the left the same and load new pages on the right frame"

This means it should get opened in "main" frame! not in "contents" frame as you asked for in "I want default.aspx to appear on the "contents" frame."

To achieve this, change the frame name as in this code (otherwise it will open in contents frame (left one! but still never the top one as you just commented that "It still redirects on the same frame.")
--------------------------------------------
Sub page_Load
        if ( not ispostback )
            drpRestaurantName.Items.add ("Peking Taste")
            drpRestaurantName.Items.add ("Jade Garden")
        else
            if (drpRestaurantName.selectedIndex = 0 )
                Response.Write("<script language=""javascript"">window.open(""default.aspx"",""main"");</script>")
            else
                Response.Write("<script language=""javascript"">window.open(""http://www.pyrius.com"",""main"");</script>")
            end if
            'Response.Write("You just selected " & drpRestaurantName.selectedItem.Value )
        end if
End Sub
--------------------------------------------

pls try again and let me know i am sure this works.

rgds,
Ajit Anand
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Expert Comment

by:ajitanand
ID: 12130479
and one more thing related to- 'Can we actually embed one language with another language?'

I am just embedding plain javascript in the HTML output from my aspx above. This means that the following script will be outputted to the client browser, and is going to execute on the client browser and not on server side.

<script language="javascript">window.open("http://www.pyrius.com","main");</script>

So we can opt for different clientside scripting language(like javascript, jscript, vbscript etc) than the server side language used in our code behind (like VB.Net, C#.Net).

rgds,
Ajit Anand
0
 

Author Comment

by:protugy
ID: 12135770
It really doesn't work. My frame name is contents not main. The top frame is banner and the bottom frame is contents. The problem with that line of code is whenever I insert the code, the other part of the code gets commented. I think the reason is because I have already got <%@ Page Language="VB" %> at the top and I don't think you can have that line and <script language = javascript>

thanks.

TJ
0
 
LVL 5

Accepted Solution

by:
ajitanand earned 250 total points
ID: 12140287
Ohh! Got it. My mistake, I did not notice that you are not using code behind and rather working in inline ASPX file.

The approach that I have suggested is still correct (but if you use code behind). To make the same idea work in inline code, we need to befool the ASPX parser in the following manner, so that it does not gets confused with opening and ending script tags.:
----------------------------------------
    Sub page_Load
        if ( not ispostback )
            drpRestaurantName.Items.add ("Peking Taste")
            drpRestaurantName.Items.add ("Jade Garden")
        else
            if (drpRestaurantName.selectedIndex = 0 )
                Response.Write("<script language=" & "javascript>window.open(""default.aspx"",""contents"");</" & "script>")
            else
                Response.Write("<script language=" & "javascript>window.open(""http://www.pyrius.com"",""contents"");</" & "script>")
            end if

            'Response.Write("You just selected " & drpRestaurantName.selectedItem.Value )
        end if
    End Sub
----------------------------------------

Give this a try now. When you see the html source (output) after running this page, you will notice that the this ascript is sent as it is on the client side to get executed.

rgds,
Ajit Anand
0
 

Author Comment

by:protugy
ID: 12140334
Excellent! thanks a lot Ajit!

I wonder why you have to put the & sign in between the language and javascript.

TJ
0
 
LVL 5

Expert Comment

by:ajitanand
ID: 12140396
the & sign in this concatenates the 2 string literals "<script language=" & "javascript>

and creates "<script language=javascript>" for the client side html.

If we dont do this, then the ASPX parser gets confused and raises error, as it assumes this to be nesting of scripts (though it is not!) with in the ASPX file.


And I belieb now you also are not get confused :)

WE know that WE are using plain vb.net on the aspx page, and spitting out javascript code (as html output).

rgds,
Ajit Anand
0
 

Expert Comment

by:klakatmm
ID: 12274500
other way

Response.Write(
"<script language=" & "javascript>self.parent.frames[""contents""].location.href = ""Index.aspx"";</" & "script>")
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Javascript to allow login/password authorization 4 63
Button to go back 3 45
Boolean 13 50
Split on ASP 8 51
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question