Thursday, March 29, 2012

Opening other ASPX pages

On the client-side you are restricted to the functionality available in
HTML. It doesn't matter what you have on the server side. What the user sees
in their browser is pure HTML.

HTH,

Kevin Spencer
Microsoft FrontPage MVP
Internet Developer
http://www.takempis.com
Big things are made up of
lots of Little things.

"Juan Dent" <juan5@dotnet.itags.org.dev.com> wrote in message
news:049201c33b74$61a1e1b0$a601280a@dotnet.itags.org.phx.gbl...
> Hi,
> If I have an ASPX page open and I press something that
> posts back to the server, then I want to open up an
> additional ASPX page passing it information from the first
> page without closing the original page.
> I have achieved some degree of success using client side
> scripting but am not really happy. It really does not do
> what I need - it just manages to open another page in its
> own window at the start.
> What I want is a *managed* way to accomplish this. I mean,
> in Windows.Forms when you want to open another window you
> create it and then Show() it. Is there nothing similar in
> ASP.NET? I can't believe that the functionality that is
> available at the HTML level, with objects like window and
> document, is not accessible from managed (compiled)
> ASP.NET code. I have been searching for classes like
> HtmlDocument or HtmlWindow with no success. If I am
> approaching this problem in the wrong manner, could
> someone please tell me the right path?
> The following is the ASPX page that opens another one:
> ------
> <%@dotnet.itags.org. Page language="c#" Codebehind="WebForm1.aspx.cs"
> AutoEventWireup="false" Inherits="SimpleWebForms.WebForm1"
> %>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0
> Transitional//EN" >
> <HTML>
> <HEAD>
> <title>WebForm1</title>
> <meta name="GENERATOR" Content="Microsoft
> Visual Studio 7.0">
> <meta name="CODE_LANGUAGE" Content="C#">
> <meta name="vs_defaultClientScript"
> content="JavaScript">
> <meta name="vs_targetSchema"
> content="http://schemas.microsoft.com/intellisense/ie5">
> </HEAD>
> <body MS_POSITIONING="GridLayout" onload="return
> OpenAnother()" >
> <form id="Form1" method="post"
> runat="server">
> <asp:Label ID="explain"
> Runat="server"/>
> <br>
> <asp:Button ID="btn" Font-
> Bold="True" Text="No runat server" />
> <asp:Button ID="ServerBtn" Font-
> Bold="True" Text="Server Button" Runat="server" />
> <input type="checkbox" name="chk"
> onclick="return ChkClick()" >
> <input type="text" name="txt" >
> <input type="hidden" id="hidden"
> name="hidden" runat= "server" >
> </form>
> <script language=javascript>
> <!--
> function ChkClick()
> {
> Form1.txt.value= "High!";
> Form1.hidden.value = Form1.ServerBtn.value
> = "Changed";
> return true;
> }
> //-->
> </script>
> <script language=javascript>
> <!--
> function OpenAnother()
> {
> window.showModelessDialog( "RequestForm.aspx");
> }
> //-->
> </script>
> </body>
> </HTML>
> ------
>
> Thanks!
> Juan DentThanks! I here what you are saying. Nevertheless is there
no way to open a second window from the aspx.cs file in C#?

Thanks again,
Juan Dent

>--Original Message--
>On the client-side you are restricted to the
functionality available in
>HTML. It doesn't matter what you have on the server side.
What the user sees
>in their browser is pure HTML.
>HTH,
>Kevin Spencer
>Microsoft FrontPage MVP
>Internet Developer
>http://www.takempis.com
>Big things are made up of
>lots of Little things.
>"Juan Dent" <juan5@.dev.com> wrote in message
>news:049201c33b74$61a1e1b0$a601280a@.phx.gbl...
>> Hi,
>>
>> If I have an ASPX page open and I press something that
>> posts back to the server, then I want to open up an
>> additional ASPX page passing it information from the
first
>> page without closing the original page.
>>
>> I have achieved some degree of success using client side
>> scripting but am not really happy. It really does not do
>> what I need - it just manages to open another page in
its
>> own window at the start.
>>
>> What I want is a *managed* way to accomplish this. I
mean,
>> in Windows.Forms when you want to open another window
you
>> create it and then Show() it. Is there nothing similar
in
>> ASP.NET? I can't believe that the functionality that
is
>> available at the HTML level, with objects like window
and
>> document, is not accessible from managed (compiled)
>> ASP.NET code. I have been searching for classes like
>> HtmlDocument or HtmlWindow with no success. If I am
>> approaching this problem in the wrong manner, could
>> someone please tell me the right path?
>>
>> The following is the ASPX page that opens another one:
>>
>> ------
>> <%@. Page language="c#" Codebehind="WebForm1.aspx.cs"
>> AutoEventWireup="false"
Inherits="SimpleWebForms.WebForm1"
>> %>
>> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0
>> Transitional//EN" >
>> <HTML>
>> <HEAD>
>> <title>WebForm1</title>
>> <meta name="GENERATOR" Content="Microsoft
>> Visual Studio 7.0">
>> <meta name="CODE_LANGUAGE" Content="C#">
>> <meta name="vs_defaultClientScript"
>> content="JavaScript">
>> <meta name="vs_targetSchema"
>> content="http://schemas.microsoft.com/intellisense/ie5">
>> </HEAD>
>> <body MS_POSITIONING="GridLayout" onload="return
>> OpenAnother()" >
>> <form id="Form1" method="post"
>> runat="server">
>> <asp:Label ID="explain"
>> Runat="server"/>
>> <br>
>> <asp:Button ID="btn" Font-
>> Bold="True" Text="No runat server" />
>> <asp:Button ID="ServerBtn" Font-
>> Bold="True" Text="Server Button" Runat="server" />
>> <input type="checkbox" name="chk"
>> onclick="return ChkClick()" >
>> <input type="text" name="txt" >
>> <input type="hidden" id="hidden"
>> name="hidden" runat= "server" >
>> </form>
>> <script language=javascript>
>> <!--
>> function ChkClick()
>> {
>> Form1.txt.value= "High!";
>> Form1.hidden.value = Form1.ServerBtn.value
>> = "Changed";
>> return true;
>> }
>> //-->
>> </script>
>> <script language=javascript>
>> <!--
>> function OpenAnother()
>> {
>> window.showModelessDialog( "RequestForm.aspx");
>> }
>> //-->
>> </script>
>> </body>
>> </HTML>
>> ------
>>
>>
>> Thanks!
>> Juan Dent
>
>.
Hello Juan,

I've set up a modal dialog using an .aspx page that handles a data update
event on the postback and then closes itself. It's a little clunky but it
works.

The important thing is to make sure that the form submit targets the same
window, otherwise the browser will open a new one. This can be done by
using the following in the window.onload

window.name = "windowName";
Form1.target = "windowName";

The second thing is communicating to the client from the postback that the
window is to be closed. I did this with a hidden input field with
runat=server, the value of thisa is checked in the window.onload of the
dialog, and if it's set to a particular value, the window is closed. I've
also communicated the value from the server back through another hidden
field.

The big fat caveat with this is it only seems to work in IE 6 - the
form.target property for modal dialogs is ignored in IE 5 (don't know about
IE 5.5 yet). As I have the luxury of developing a fixed IE6+ client, it's
not a problem.

I've attached a demo, and the source here.

Hope it helps...

Best regards,
yhhuang
VS.NET, Visual C++
Microsoft

This posting is provided "AS IS" with no warranties, and confers no rights.
Got .Net? http://www.gotdotnet.com
-------
!Content-Class: urn:content-classes:message
!From: "Juan Dent" <juan5@.dev.com>
!Sender: "Juan Dent" <juan5@.dev.com>
!References: <049201c33b74$61a1e1b0$a601280a@.phx.gbl>
<OfH1p09ODHA.2224@.TK2MSFTNGP10.phx.gbl>
!Subject: Re: Opening other ASPX pages
!Date: Thu, 26 Jun 2003 09:40:13 -0700
!Lines: 121
!Message-ID: <007901c33c01$9ddcc130$a401280a@.phx.gbl>
!MIME-Version: 1.0
!Content-Type: text/plain;
!charset="iso-8859-1"
!Content-Transfer-Encoding: 7bit
!X-Newsreader: Microsoft CDO for Windows 2000
!Thread-Index: AcM8AZ3cmThxGY7qRw+s473yMPXqFQ==
!X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
!Newsgroups: microsoft.public.dotnet.framework.aspnet
!Path: cpmsftngxa06.phx.gbl
!Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:155155
!NNTP-Posting-Host: TK2MSFTNGXA12 10.40.1.164
!X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
!
!Thanks! I here what you are saying. Nevertheless is there
!no way to open a second window from the aspx.cs file in C#?
!
!Thanks again,
!Juan Dent
!
!>--Original Message--
!>On the client-side you are restricted to the
!functionality available in
!>HTML. It doesn't matter what you have on the server side.
!What the user sees
!>in their browser is pure HTML.
!>
!>HTH,
!>
!>Kevin Spencer
!>Microsoft FrontPage MVP
!>Internet Developer
!>http://www.takempis.com
!>Big things are made up of
!>lots of Little things.
!>
!>"Juan Dent" <juan5@.dev.com> wrote in message
!>news:049201c33b74$61a1e1b0$a601280a@.phx.gbl...
!>> Hi,
!>>
!>> If I have an ASPX page open and I press something that
!>> posts back to the server, then I want to open up an
!>> additional ASPX page passing it information from the
!first
!>> page without closing the original page.
!>>
!>> I have achieved some degree of success using client side
!>> scripting but am not really happy. It really does not do
!>> what I need - it just manages to open another page in
!its
!>> own window at the start.
!>>
!>> What I want is a *managed* way to accomplish this. I
!mean,
!>> in Windows.Forms when you want to open another window
!you
!>> create it and then Show() it. Is there nothing similar
!in
!>> ASP.NET? I can't believe that the functionality that
!is
!>> available at the HTML level, with objects like window
!and
!>> document, is not accessible from managed (compiled)
!>> ASP.NET code. I have been searching for classes like
!>> HtmlDocument or HtmlWindow with no success. If I am
!>> approaching this problem in the wrong manner, could
!>> someone please tell me the right path?
!>>
!>> The following is the ASPX page that opens another one:
!>>
!>> ------
!>> <%@. Page language="c#" Codebehind="WebForm1.aspx.cs"
!>> AutoEventWireup="false"
!Inherits="SimpleWebForms.WebForm1"
!>> %>
!>> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0
!>> Transitional//EN" >
!>> <HTML>
!>> <HEAD>
!>> <title>WebForm1</title>
!>> <meta name="GENERATOR" Content="Microsoft
!>> Visual Studio 7.0">
!>> <meta name="CODE_LANGUAGE" Content="C#">
!>> <meta name="vs_defaultClientScript"
!>> content="JavaScript">
!>> <meta name="vs_targetSchema"
!>> content="http://schemas.microsoft.com/intellisense/ie5">
!>> </HEAD>
!>> <body MS_POSITIONING="GridLayout" onload="return
!>> OpenAnother()" >
!>> <form id="Form1" method="post"
!>> runat="server">
!>> <asp:Label ID="explain"
!>> Runat="server"/>
!>> <br>
!>> <asp:Button ID="btn" Font-
!>> Bold="True" Text="No runat server" />
!>> <asp:Button ID="ServerBtn" Font-
!>> Bold="True" Text="Server Button" Runat="server" />
!>> <input type="checkbox" name="chk"
!>> onclick="return ChkClick()" >
!>> <input type="text" name="txt" >
!>> <input type="hidden" id="hidden"
!>> name="hidden" runat= "server" >
!>> </form>
!>> <script language=javascript>
!>> <!--
!>> function ChkClick()
!>> {
!>> Form1.txt.value= "High!";
!>> Form1.hidden.value = Form1.ServerBtn.value
!>> = "Changed";
!>> return true;
!>> }
!>> //-->
!>> </script>
!>> <script language=javascript>
!>> <!--
!>> function OpenAnother()
!>> {
!>> window.showModelessDialog( "RequestForm.aspx");
!>> }
!>> //-->
!>> </script>
!>> </body>
!>> </HTML>
!>> ------
!>>
!>>
!>> Thanks!
!>> Juan Dent
!>
!>
!>.
!>
!

1 comments:

josphene said...

Nice blog and absolutely outstanding. You can do something much better but i still say this perfect.Keep trying for the best. schlüsseldienst kosten

Post a Comment