Solved

redirect pages to another frame in ASP.NET

Posted on 2004-09-21
9
581 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
  • 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now