Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Run client script after postback

Run client script after postback

Scheduled Pinned Locked Moved ASP.NET
javascriptsysadmintoolsquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    chubbysilk
    wrote on last edited by
    #1

    Hello, I would like to post back to the server, set a few session variables there, and then run a javascript function on the client side which redirects a particular frame. Essentially I want to run some client script after posting back. Is that possible? Thanks, RC

    M R 2 Replies Last reply
    0
    • C chubbysilk

      Hello, I would like to post back to the server, set a few session variables there, and then run a javascript function on the client side which redirects a particular frame. Essentially I want to run some client script after posting back. Is that possible? Thanks, RC

      M Offline
      M Offline
      Mike Ellison
      wrote on last edited by
      #2

      Hi RC. So the post to the server is happening in frame #1, and you'd like to then have the response in frame #1 signal a redirect in frame #2?

      C 1 Reply Last reply
      0
      • C chubbysilk

        Hello, I would like to post back to the server, set a few session variables there, and then run a javascript function on the client side which redirects a particular frame. Essentially I want to run some client script after posting back. Is that possible? Thanks, RC

        R Offline
        R Offline
        Radoslav Bielik
        wrote on last edited by
        #3

        I don't know if this would be a proper solution, but you could use

        if(Page.IsPostBack)
        Page.RegisterStartupScript("my_redirect_script", TheScriptItSelf);

        Rado


        Radoslav Bielik http://www.neomyz.com/poll [^] - Get your own web poll

        1 Reply Last reply
        0
        • M Mike Ellison

          Hi RC. So the post to the server is happening in frame #1, and you'd like to then have the response in frame #1 signal a redirect in frame #2?

          C Offline
          C Offline
          chubbysilk
          wrote on last edited by
          #4

          Yep, that's what I would like to do.

          M 1 Reply Last reply
          0
          • C chubbysilk

            Yep, that's what I would like to do.

            M Offline
            M Offline
            Mike Ellison
            wrote on last edited by
            #5

            Hi there. Try this out - copy each of these blocks to four seperate files with the given names, then load frames.htm in your browser. I'm using a Literal control in frames1.aspx to output the necessary javascript to redirect the second frame. File 1 - frames.htm

            <html>
            <head>
            <frameset cols="*, 50%">
            <frame name="frame1" src="frame1.aspx">
            <frame name="frame2" src="frame2a.aspx">
            </frameset>
            </head>
            </html>

            File 2 - frame1.aspx

            <%@Page Language="C#" %>
            <script runat="server">
            void HandleSubmit(Object o, EventArgs e)
            {
            Session["Var1"] = txtVar1.Text;
            Session["Var2"] = txtVar2.Text;

                string sRedirect 
                  = "parent.frame2.location.href = 'frame2b.aspx';";
                
                literalRedirect.Text = sRedirect;
            }
            

            </script>

            <html>
            <head>
            <script language="javascript">
            <asp:Literal runat="server" id="literalRedirect" />
            </script>
            </head>
            <body>
            <form runat="server">
            <h3>This is Frame 1</h3>
            Enter what you want for session variables
            <table>
            <tr><td>Var1</td>
            <td><asp:TextBox runat="server" id="txtVar1"/></td>
            </tr>
            <tr><td>Var2</td>
            <td><asp:TextBox runat="server" id="txtVar2"/></td>
            </tr>
            </table>
            <asp:Button runat="server" id="btnSubmit"
            text="Submit" onClick="HandleSubmit" />
            </form>
            </body>
            </html>

            File 3 - frame2a.aspx

            <html>
            <head></head>
            <body>
            <form runat="server">
            <h3>This is Frame 2</h3>
            BEFORE the redirection
            </form>
            </body>
            </html>

            File 4 - frame2b.aspx

            <%@ Page language="C#" %>
            <script runat="server">
            void Page_Load(Object o, EventArgs e)
            {
            literal1.Text = Session["Var1"].ToString();
            literal2.Text = Session["Var2"].ToString();
            }
            </script>

            <html>
            <head></head>
            <body>
            <form runat="server">

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups