Wrox Programmer Forums
|
ASP.NET 1.x and 2.0 Application Design Application design with ASP.NET 1.0, 1.1, and 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.x and 2.0 Application Design section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 5th, 2004, 10:45 AM
Authorized User
 
Join Date: Oct 2004
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Default window.open() problem

I have a button that click on it should do:


Private Sub Check_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Check.Click

        Dim strFirstName= Me.firstName.Text
        Dim strFamilyName= Me.familyName.Text
        Dim strYearArrive = Me.selectYear.SelectedValue


window.open('CheckStudet.aspx?firstName='+strFirst Name+
'&familyName=' +strFamilyName+ '&YearArrive =' +strYearArrive ,'Check','width=500,height=250,directories=no,loca tion=no,menubar=no,scrollbars=no,status=no,toolbar =no,resizable=no');

    End Sub


In fact I want to open saperate window. but my code is incorect!
How to do it?


 
Old December 8th, 2004, 11:18 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

   window.open() is a javascript function. You need to create a javascript function in the <script> area of your HTML. Then call that function from your click event. In order to run both server side code and client side code from your code behind event, you need to use the Page.RegisterClientScriptBlock Method or the Page.RegisterStartupScript Method.

 
Old December 16th, 2004, 01:23 PM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

Another possibility,
Code:
private void Page_Load(object sender, System.EventArgs e)
{
    if(!Page.IsPostBack)
    {
           string s="";
           s+="window.open('URL','Description','');";
           Button.Attributes.Add("onclick",s);
    }
}
private void Button_Click(object sender, System.EventArgs e)
{
      //put codes execute on the server-side after opening new window
}
_____________________________
Mehdi.
software engineering student.
Looking for a good job for summer 2005.
 
Old December 22nd, 2004, 09:38 AM
Authorized User
 
Join Date: Sep 2004
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to nashnash
Default

Copy and paste the code you will get the desired output.

--save this as 'WebForm2.aspx' ---------------
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm2.aspx.vb" Inherits="VB.WebForm2"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
    <HEAD>
        <title>WebForm2</title>
        <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
        <meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
        <meta name="vs_defaultClientScript" content="JavaScript">
        <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
        <script language="javascript">
            function openMyWindow()
            {
                var strFirstName;
                var strFamilyName;
                var selYear;
                var strURL;
                strFirstName=document.getElementById("firstName"). value;
                strFamilyName=document.getElementById("familyName" ).value;
                strYearArrive=document.getElementById("selectYear" ).value;
                strURL="CheckStudet.aspx?firstName="+strFirstName+ "&familyName="+strFamilyName+"&YearArrive="+strYea rArrive;

                window.open(strURL,"Check","width=500,height=250,d irectories=no,location=no,menubar=no,scrollbars=no ,status=no,toolbar=no,resizable=no");
                return false;
            }
        </script>
    </HEAD>
    <body MS_POSITIONING="GridLayout">
        <form id="Form1" method="post" runat="server">
            <asp:TextBox id="firstName" style="Z-INDEX: 101; LEFT: 200px; POSITION: absolute; TOP: 72px"
                runat="server"></asp:TextBox>
            <asp:TextBox id="familyName" style="Z-INDEX: 102; LEFT: 200px; POSITION: absolute; TOP: 112px"
                runat="server"></asp:TextBox>
            <asp:DropDownList id="selectYear" style="Z-INDEX: 103; LEFT: 200px; POSITION: absolute; TOP: 152px"
                runat="server">
                <asp:ListItem Value="2000" Selected="True">2000</asp:ListItem>
                <asp:ListItem Value="2001">2001</asp:ListItem>
                <asp:ListItem Value="2002">2002</asp:ListItem>
                <asp:ListItem Value="2003">2003</asp:ListItem>
                <asp:ListItem Value="2004">2004</asp:ListItem>
            </asp:DropDownList>
            <asp:Button id="Check" style="Z-INDEX: 104; LEFT: 208px; POSITION: absolute; TOP: 192px" runat="server"
                Text="Button"></asp:Button>
        </form>
    </body>
</HTML>


----Save this as 'WebForm2.aspx.vb' ------
Public Class WebForm2
    Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents firstName As System.Web.UI.WebControls.TextBox
    Protected WithEvents familyName As System.Web.UI.WebControls.TextBox
    Protected WithEvents selectYear As System.Web.UI.WebControls.DropDownList
    Protected WithEvents Check As System.Web.UI.WebControls.Button

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Check.Attributes.Add("onclick", "javascript:openMyWindow();")
    End Sub

End Class


-------

Thanks
Nash






Similar Threads
Thread Thread Starter Forum Replies Last Post
open window problem geogomez Javascript How-To 2 December 9th, 2005 05:23 AM
Open New Window b_camp Classic ASP Basics 2 May 12th, 2005 01:19 AM
Problem with window.open fs22 Javascript 9 April 28th, 2004 11:32 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.