• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 608
  • Last Modified:

redirect pages to another frame in ASP.NET

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
protugy
Asked:
protugy
  • 5
  • 3
1 Solution
 
ajitanandCommented:
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
 
protugyAuthor Commented:
It doesn't work. It still redirects on the same frame.
Can we actually embed one language with another language?

thanks.

TJ
0
 
ajitanandCommented:
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
ajitanandCommented:
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
 
protugyAuthor Commented:
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
 
ajitanandCommented:
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
 
protugyAuthor Commented:
Excellent! thanks a lot Ajit!

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

TJ
0
 
ajitanandCommented:
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
 
klakatmmCommented:
other way

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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now