[Webinar] Learn how to a build a cloud-first strategyRegister Now

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

code to change url on another frame? or code to click the hyperlink object?

Hi -

I have a frame page top frame, and bottom frame
on the top frame I have a drop down box
It has a few webpages listed in it.
I'd like to load the webpage in the bottom frame when it's selected.

I have a sub Dropdownlist1_selectedindexchanged(..)

what would I put inside that?

So far my page only imports System.web.UI.Page - and I didnt see any frame targeting code in the object browser.


on another note, I tried to include a hyperlink on the top frame, that works just fine and launches the page I want in the lower frame.

Could my selectedindexchanged() sub call the hyperlink somehow? I tried hyperlink1 but VS2003 underlines it in blue - doesn't know what I'm talking about.

- Jack
2 Solutions
Jesse HouwingScrum Trainer | Microsoft MVP | ALM Ranger | ConsultantCommented:
You'll need to use a javascript solution instead, as ASP.net has no influence on link target's from codebehind

See http://www.pageresource.com/jscript/jdropbox.htm as an example.

Please not that you can ofcourse generate this javascript from the codebehind if you wanted to.
write the following code in selectionchanged event:-

         string script   = "<SCRIPT>"
                  script += " document.Frame2.location.href = 'your page.htm'";
                  script += "</SCRIPT>";

so, this script will be executed while the selection is changed.
plz post here if this is works out for your requirement.

Vadivel Kumar
fruhjAuthor Commented:
Thanks both of you guys so far, I'm aware I can get some javascipt to do the work - had been wondering if this was supported directly by the .net framework - looks like it's not.

Vadivhere - can you clarify a bit

the page.registerclientscriptBlock("selection", Script);
what does "selection" refer to - if my control was called DropDownList1, what do I need to do to ensure that the client javascript you put in gets executed on a change event, instead of posting back to the server?
So i assume that u have a dropdowlist1 which has the value set as the page name where u want to navigate and the text set as the name that has to be displayed to the user .. if so add this line in the load of the page ..
dropdownlist1.attributes.add("Onchange", "javascript:LoadNewPage();")
.. this will call a function on the client-side (browser) whenever the selection in the dropdown changes .. remeber to set the autopostback property of the dropdown to "false"

in the aspx page add the new function
<script language = "javascript">
function LoadNewPage()
   top.frames("bottomFrameName").location.href = document.getElementById("DropDownList1").value;

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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