[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

window.open problem

Posted on 2004-04-14
5
Medium Priority
?
735 Views
Last Modified: 2008-02-01
I have an asp and a page with two frames. (content,main)
I would like to show the page on a different frame.
Here is what I have:

I am working in C#


void MYSelectedChangeEventHandlerFunction(DropDownList DD)
{
try
{
string address = DD.SelectedItem.Value;
//Response.Redirect("address");
Response.Write(" <script> window.open(address,main); </script> ")
}
catch(Exception ex)
{
DD.Items.Add("Dir Errors Found!");
}
       
}

What AM I doing wrong?
Is there a better way to out put the page to a different frame within the function.
Help!
Thanks, Redirect to different page

}
0
Comment
Question by:howard7890
[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 Comments
 
LVL 6

Expert Comment

by:KarunSK
ID: 10829322
Check this link:

http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/Q_20932666.html

The code is in VB, but that shouldn't matter.

HTH,
Karun.
0
 

Accepted Solution

by:
rasaraja earned 500 total points
ID: 10829329
Response.Write(" <script language=javascript>
window.open('" + address + "')</script> ")

Note the single quotes around the double quotes. To load a page in a particular frame, specify the target property of window. Since you want to open in a new window, don't specify it.

I would suggest that you handle this event in the client side, if that is the only thing you are doing. Otherwise you can put the window.open stuff in window.onload , execute it based on a flag that you set in code-behind.
Regards,
Ras


0
 
LVL 2

Expert Comment

by:waterhidden
ID: 10830311
when using dynamic javascript in .net pages, you're better to use this in codebehind

        dim strScript as string = "<script> " & _ 'any javascript code here, you can put value of dropdownlist or etc...
        "setTimeout('self.close()',2000); " & _
        "</script>"

        RegisterClientScriptBlock("anything", strScript)

this is vb code, but you can easily convert it to c#


hope it works..
0
 

Author Comment

by:howard7890
ID: 10835142
I have added this code from above I still get an error when I try to compile.
There is somthing simple I am doing wrong but I have no idea what it might be.

Here Is my ASP.
I just need to send the page to a different page.
Thanks,
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Data" %>
<%@ Page Language="C#" Debug="true" %>
<HTML>
<script runat="server">
string Path;

public void Init()
{
int w = 125;
bool Fontbold = true;
int Fontsize = 8;
string FontName = "Verdona";

Path = Server.MapPath("\\");

DDList.Width = w;
Dropdownlist1.Width = w;
Dropdownlist2.Width = w;
Summary.Width = w;
Log.Width = w;

}

public void AutoSetBack()
//Reset all controls to set the autosetback to false
{
      DDList.AutoPostBack = false;
      Dropdownlist1.AutoPostBack = false;
      Dropdownlist2.AutoPostBack = false;
      Summary.AutoPostBack = false;
      Log.AutoPostBack = false;
      Misc.AutoPostBack = false;
}
//Clear all controls under the selected control
public void ClearAll(string StartTag)
{
      switch(StartTag)
      {
            case "All":
                  goto All;
                  break;
            case "Family":
                  goto Family;
                  break;
            case "WWSV":
                  goto WWSV;
                  break;
            case "TD":
                  goto TD;
                  break;
      }

All:
      DDList.Items.Clear();
Family:
      Dropdownlist1.Items.Clear();
WWSV:
      Dropdownlist2.Items.Clear();
TD:
      Summary.Items.Clear();
      Log.Items.Clear();
      Misc.Items.Clear();
}


public string GetName(string fullpath)
{
                  char[] cDividers = {'\\'};
                  string[] segment;
                  segment = fullpath.Split(cDividers);
                  int length = segment.Length-1;
                  return segment[length].ToString();
}

void Page_Load(object sender, EventArgs e)
      {
            try
            {
                  if (!Page.IsPostBack)
                        {
                              Init();
                              LoadRest(1,"\\Family");
                              Page.DataBind();
                        }
            }
            catch(Exception ex)
                  {
                        ;
                  }
      }
public void PopDD (DropDownList DD,string FullPath,int choice)
{
      try
      {
            string[] dirs = Directory.GetDirectories(FullPath);
            foreach (string dir in dirs)
            {
                  DD.Items.Add(new ListItem(GetName(dir), dir));
            }
            DD.SelectedIndex = dirs.Length-1;
            if (DD.SelectedIndex != -1)
            {
                  LoadRest(++choice,DD.SelectedItem.Value);
            }
      }
      catch(Exception ex)
            {
                  DD.Items.Add("Dir Errors Found!");
            }
}


//Loads the rest of the directories
void LoadRest(int choice,string value)
      {
                        
            switch(choice)
            {
                  case 1:
                        PopDD(DDList,value,1);
                        break;
                  case 2:
                        PopDD(Dropdownlist1,value,2);
                        break;
                  case 3:
                        PopDD(Dropdownlist2,value,3);
                        break;
                  case 4:
                        Loadfiles(value);
                        break;
                  case 5:
                        //getLog
                        break;
                  case 6:
                        //getMisc;
                        break;
                  case 7:
                  break;
                  
            }
      }

void FamilyChangeEventHandlerFunction(object sender, EventArgs e)
{
      ClearAll("Family");
      LoadRest(2,DDList.SelectedItem.Value);
}
void WWSVChangeEventHandlerFunction(object sender, EventArgs e)
{
      ClearAll("WWSV");
      LoadRest(3,Dropdownlist1.SelectedItem.Value);
}
void TDChangeEventHandlerFunction(object sender, EventArgs e)
{
      ClearAll("TD");
      LoadRest(4,Dropdownlist2.SelectedItem.Value);
}

void SummaryChangeEventHandlerFunction(object sender, EventArgs e)
{MYSelectedChangeEventHandlerFunction(Summary);
}
void LogChangeEventHandlerFunction(object sender, EventArgs e)
{MYSelectedChangeEventHandlerFunction(Log);
}
void MiscChangeEventHandlerFunction(object sender, EventArgs e)
{MYSelectedChangeEventHandlerFunction(Misc);
}


void MYSelectedChangeEventHandlerFunction(DropDownList DD)
{
            AutoSetBack();
            Response.Buffer = true;
            Response.Clear();
            string address = DD.SelectedItem.Value;
            Response.Redirect(address);
            Response.Write(" <script language=javascript> window.open('" + address + "')</script> ");
      
}
void Loadfiles(string dir)
      {
            string fullpath;
            FileInfo[] Sum,LogFiles,MiscFiles;
            DirectoryInfo DirInfo;

                  fullpath = dir + "\\Summary";
                  DirInfo = new DirectoryInfo(fullpath);
                  if (DirInfo.Exists)
                        {
                        Sum = DirInfo.GetFiles();
                        foreach (FileInfo SumTemp in Sum)
                              {
                                    if (SumTemp.Extension.ToUpper() == ".HTM")
                                          {
                                                Summary.Items.Add(new ListItem(SumTemp.Name, SumTemp.FullName));
                                          }
                              }
                        }
                  fullpath = dir + "\\Log";
                  DirInfo = new DirectoryInfo(fullpath);
                  if (DirInfo.Exists)
                        {
                        LogFiles = DirInfo.GetFiles();
                        foreach (FileInfo LogTemp in LogFiles)
                              {
                                    if (LogTemp.Extension.ToUpper() == ".XML")
                                          {
                                                Log.Items.Add(new ListItem(LogTemp.Name, LogTemp.FullName));
                                          }
                              }
                        }
                  if (DirInfo.Exists)
                        {      
                        fullpath = dir + "\\Misc";
                        DirInfo = new DirectoryInfo(fullpath);
                        MiscFiles = DirInfo.GetFiles();
                        string Ext;
                        foreach (FileInfo MiscTemp in MiscFiles)
                              {
                                    Ext=MiscTemp.Extension.ToUpper();
                                    if (Ext == ".PPT" ||Ext == ".PDF" ||Ext == ".PIF"||Ext == ".BMP")
                                          {
                                                Misc.Items.Add(new ListItem(MiscTemp.Name, MiscTemp.FullName));
                                          }
                        
                              }
                        }
            Page.DataBind();
      }

      </script>
      <form runat="server" ID="Form1">
            <asp:Label Font-Name="Verdana" Font-Bold="True" Font-Size="8" id="Label1" runat="server" text="Family" /><br>
            <asp:dropdownlist Font-Name="Verdana" Font-Bold="True" Font-Size="8" autopostback="true" runat="server" id="DDList" OnSelectedIndexChanged="FamilyChangeEventHandlerFunction" />
            <P></P>
            <asp:Label id="Label2" runat="server" text="Work Week - Silicon Rev" /><br>
            <asp:dropdownlist autopostback="true" runat="server" id="Dropdownlist1" OnSelectedIndexChanged="WWSVChangeEventHandlerFunction" />
            <P></P>
            <asp:Label id="Label3" runat="server" text="Test Date" /><br>
            <asp:dropdownlist autopostback="true" runat="server" id="Dropdownlist2" OnSelectedIndexChanged="TDChangeEventHandlerFunction" />
            <P></P>
            <asp:Label id="Label4" runat="server" text="Summary" /><br>
            <asp:dropdownlist OnSelectedIndexChanged="SummaryChangeEventHandlerFunction" autopostback="true" runat="server" id="Summary" />
            <asp:Button id="Button1" Text="Go" runat="server" OnClick="SummaryChangeEventHandlerFunction" />
            <P></P>
            <asp:Label id="Label5" runat="server" text="Log Files" /><br>
            <asp:dropdownlist OnSelectedIndexChanged="LogChangeEventHandlerFunction" autopostback="true" runat="server" id="Log" />
            <asp:Button id="b1" Text="Go" runat="server" OnClick="LogChangeEventHandlerFunction" />
            <P></P>
            <asp:Label id="Label6" runat="server" text="Misc Support Files" /><br>
            <asp:dropdownlist OnSelectedIndexChanged="MiscChangeEventHandlerFunction" autopostback="true" runat="server" id="Misc" />
            <asp:Button id="Button2" Text="Go" runat="server" OnClick="MiscChangeEventHandlerFunction" />
            <input type="button" Value="Open Window" ONCLICK="window.open(Test)"></form> <!-- -->
      </form> <input type="button" value="Go" name="B1" onclick="window.open()">
      <!-- -->
      <FORM>
            <input type="button" Value="Open Window" ONCLICK="window.open('http://www.developer.com')"></FORM> <!-- -->
      <a href="javascript:void window.open('http://www.developer.com', 'windowTitle', 'height=500,width=700,status=0')">
            click here</a> </BODY>
</HTML>
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

650 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