Closing One WebForm from another Webform

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • VijaySofist
    New Member
    • Jun 2007
    • 107

    Closing One WebForm from another Webform

    Hi All!

    I want to close one web form thro another web form coding(i.e thro server side coding). Can Anybody help me for this.

    I am using Asp.Net 2.0 with VB Coding in Microsoft XP Machine.

    Thanks in Advance

    With Regards
    Vijay. R
  • yumbelie
    New Member
    • Dec 2007
    • 9

    #2
    Originally posted by VijaySofist
    Hi All!

    I want to close one web form thro another web form coding(i.e thro server side coding). Can Anybody help me for this.

    I am using Asp.Net 2.0 with VB Coding in Microsoft XP Machine.

    Thanks in Advance

    With Regards
    Vijay. R
    You can't really do it server-side, since the client is responsible for managing which windows are open and which are closed - and to ackle client-side operations (like closing one browser window and opening another one) you'd need to use JavaScript.

    Because web browsing is event based (E.g. the server sends the client browser a page, the client browser does something with it - e.g. fill out a few input boxes, and then submits it - the server recieves the response, then processes it) you will need to make the client raise an event, so the server knows they want to receive the next webform.

    A couple of solutions might be:

    A) Stream JavaScript out with the first webform that sets a timer (see setTimeout() method), and after a certain time submits the page, allowing the server to stream the next page.

    B) If the second webform is in another browser window, investigate the Javascript window.close() method (w3schools.com is good for all this).

    You could stream the necessary JavaScript to the client in a seperate .js file as a webresource (do a google for asp webresource), or you could embed it in the webforms declarative markup:

    Code:
    <script type="text/javascript">
    
     function helloWorld()
     {
      alert('hello');
    } 
    
    </script>
    <asp:Button runat="server" id="testbutton" text="Hello World!" OnClientClick="helloWorld();return false;" />
    Hope that's some help.

    Comment

    • kunal pawar
      Contributor
      • Oct 2007
      • 297

      #3
      Hi,
      using server code u can not close client browser but using javascript u can close client browse.

      But before that u have to set parent of browser so it will not ask for close browser message
      use window.close() method to close browser

      Comment

      • VijaySofist
        New Member
        • Jun 2007
        • 107

        #4
        Hi All!

        Thanks for the Response. I can't use the javascript because when using javascript I can close only the current window. I want to make a function in ASP.Net Server side code that will end the webform whereever I Call.

        Thanks in Advance
        Vijay. R

        Comment

        • deric
          New Member
          • Dec 2007
          • 92

          #5
          Hi..
          Are you trying to close the webpage that opened the new webpage?
          If so, you can do this on client side with javascript using its "opener" object.

          I made a simple simulation:
          Code:
          test1.html:
          <html>
          ...
          <a href="#" onclick="javascript:window.open('test2.html');">open</a>
          ...
          </html>
          
          
          test2.html:
          <html>
          ..
          <script language="javascript">
          opener.close();
          </script>
          ...
          </html>

          Comment

          • VijaySofist
            New Member
            • Jun 2007
            • 107

            #6
            Hi All!

            I found the code to close one webform from the other webform thro the server side coding.

            This is the Code.
            [CODE=vb]
            Me.ClientScript .RegisterClient ScriptBlock(Me. GetType, "my_window" , "<SCRIPT language=JavaSc ript1.2>window. close();</SCRIPT>")
            [/CODE]

            We can call this any where around the webform in the server Side coding to cose the webform.

            Thanks for all who responded me.

            With Regards
            Vijay. R

            Comment

            Working...