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

window.open problem

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
howard7890
Asked:
howard7890
1 Solution
 
KarunSKCommented:
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
 
rasarajaCommented:
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
 
waterhiddenCommented:
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
 
howard7890Author Commented:
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

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

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