Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

redirect pages to another frame in ASP.NET

Posted on 2004-09-21
9
Medium Priority
?
600 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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 1000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

670 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