ClientScript.RegisterStartScript exexuting on page reload

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Danielle

    ClientScript.RegisterStartScript exexuting on page reload

    Greetings all -

    I am working on a vb .NET asp web application. I have a button that
    opens a new page when clicked. It works fine; the problem is when the
    user refreshes the original page, the script executes again even
    though the button hasn't been clicked.

    Here's the sub - the button is a standard ASP button with no
    frills...

    Protected Sub btnNew_Click(By Val sender As Object, ByVal e As
    System.EventArg s) Handles btnNew.Click

    Const INSERT_PAGE As String = "AddNewContact. aspx"
    Dim URLArg As String = INSERT_PAGE & "?agreement ID=" &
    agreementID
    ClientScript.Re gisterStartupSc ript(Me.GetType , "popup",
    "window.ope n('" & BASEURL & URLArg & "','_blank','me nubar=yes')",
    True)

    End Sub

    This is making me a little crazy - any help would be greatly
    appreciated. I've seen that others have had this problem, but can't
    find any solution yet...

    Thanks!
    Danielle
  • =?Utf-8?B?YnJ1Y2UgYmFya2Vy?=

    #2
    RE: ClientScript.Re gisterStartScri pt exexuting on page reload

    rendering inline openwindows is poor design. for this to work, your users
    have to turn off their popup blockers. you really shoudl just attach the
    javascript to the button, and not do a postback.

    anyway to fix your problem, on the page render a request guid in a hidden
    field and also store this on the server. when the button is clicked, check to
    see if the request has already been processed, if so take some action, else
    process as normal, and mark the request as processed.

    -- bruce (sqlwork.com)


    "Danielle" wrote:
    Greetings all -
    >
    I am working on a vb .NET asp web application. I have a button that
    opens a new page when clicked. It works fine; the problem is when the
    user refreshes the original page, the script executes again even
    though the button hasn't been clicked.
    >
    Here's the sub - the button is a standard ASP button with no
    frills...
    >
    Protected Sub btnNew_Click(By Val sender As Object, ByVal e As
    System.EventArg s) Handles btnNew.Click
    >
    Const INSERT_PAGE As String = "AddNewContact. aspx"
    Dim URLArg As String = INSERT_PAGE & "?agreement ID=" &
    agreementID
    ClientScript.Re gisterStartupSc ript(Me.GetType , "popup",
    "window.ope n('" & BASEURL & URLArg & "','_blank','me nubar=yes')",
    True)
    >
    End Sub
    >
    This is making me a little crazy - any help would be greatly
    appreciated. I've seen that others have had this problem, but can't
    find any solution yet...
    >
    Thanks!
    Danielle
    >

    Comment

    • Danielle

      #3
      Re: ClientScript.Re gisterStartScri pt exexuting on page reload

      Bruce -

      Thanks for the suggestion. I'd rather do this properly but am fairly
      new to programming and having to do this outside of my normal role.
      Which is to say I've been using code bits I've found on the web a LOT.

      When you say attach the javascript to the button I'm not sure what you
      mean or how it would be implemented. Can you provide a sample? Please
      note that I need to pass a parameter to the page that is loaded on the
      button click.

      Danielle

      Comment

      • Nick Gilbert

        #4
        Re: ClientScript.Re gisterStartScri pt exexuting on page reload

        Danielle,

        Don't attempt to implement it this way - the vast majority of people use
        pop-up blockers and it won't work. Windows opening on their own when you
        haven't done anything is REALLY REALLY annoying which is why the popup
        blocker was invented.

        I really don't understand why you're doing it that way in the first
        place. If you want a button that opens a window when you click it, just
        put the window.open command in the onclick event of that button! Why are
        you posting back to the *server* to open a new window client side??

        You don't need any server side code for this.

        <a href="javascrip t:window.open(< blah>)">open me</a>

        Ideally, so that it works in browsers which don't have javascript enabled:

        <a href="page.html " target="_blank"
        onclick="javasc ript:window.ope n(<blah>); return false;">open me</a>

        The return false bit prevents it from opening the window using
        javascript AND navigating to the site in the background. If the user has
        JS disabled, it will still open in a new window, but you won't be able
        to specify the size or position of the new window.

        Opening the window using client side code only will also be much quicker
        as it won't postback to the server before opening the window.

        Nick...

        Danielle wrote:
        Greetings all -
        >
        I am working on a vb .NET asp web application. I have a button that
        opens a new page when clicked. It works fine; the problem is when the
        user refreshes the original page, the script executes again even
        though the button hasn't been clicked.
        >
        Here's the sub - the button is a standard ASP button with no
        frills...
        >
        Protected Sub btnNew_Click(By Val sender As Object, ByVal e As
        System.EventArg s) Handles btnNew.Click
        >
        Const INSERT_PAGE As String = "AddNewContact. aspx"
        Dim URLArg As String = INSERT_PAGE & "?agreement ID=" &
        agreementID
        ClientScript.Re gisterStartupSc ript(Me.GetType , "popup",
        "window.ope n('" & BASEURL & URLArg & "','_blank','me nubar=yes')",
        True)
        >
        End Sub
        >
        This is making me a little crazy - any help would be greatly
        appreciated. I've seen that others have had this problem, but can't
        find any solution yet...
        >
        Thanks!
        Danielle

        Comment

        • Danielle

          #5
          Re: ClientScript.Re gisterStartScri pt exexuting on page reload

          Well, I'm doing it because I really don't know what I'm doing...

          <asp:Button ID="btnNew" runat="server" Font-Bold="true" Font-
          Names="verdana"
          font-size="small" Text="Add New Contact"
          onclick="window .open('www.micr osoft.com'); return false;" /
          ><br /><br />
          Give me an error "BC30456: 'window' is not a member of
          'ASP.details_as px'." (details.aspx is the name of the page I amt
          trying to load).

          Comment

          • Nick Gilbert

            #6
            Re: ClientScript.Re gisterStartScri pt exexuting on page reload

            Danielle wrote:
            Well, I'm doing it because I really don't know what I'm doing...
            >
            <asp:Button ID="btnNew" runat="server" Font-Bold="true" Font-
            Names="verdana"
            font-size="small" Text="Add New Contact"
            onclick="window .open('www.micr osoft.com'); return false;" /
            ><br /><br />
            >
            Give me an error "BC30456: 'window' is not a member of
            'ASP.details_as px'." (details.aspx is the name of the page I amt
            trying to load).

            You can't (and don't need to) use an asp:Button control for this. It
            will be client side function only, so you shouldn't need to use a
            server-side control. Just use a normal HTML button or link.

            ie
            <input type=button onclick="window .open();" value="Click Me" />

            The onclick event of an asp:Button control is code to be executed on the
            server in VB or C# etc... The onclick event of a normal HTML button is
            javascript to be run locally within the browser.

            Hope this makes sense!

            Nick...

            Comment

            • Nick Gilbert

              #7
              Re: ClientScript.Re gisterStartScri pt exexuting on page reload

              Danielle wrote:
              Well, I'm doing it because I really don't know what I'm doing...
              >
              <asp:Button ID="btnNew" runat="server" Font-Bold="true" Font-
              Names="verdana"
              font-size="small" Text="Add New Contact"
              onclick="window .open('www.micr osoft.com'); return false;" /
              ><br /><br />
              >
              Give me an error "BC30456: 'window' is not a member of
              'ASP.details_as px'." (details.aspx is the name of the page I amt
              trying to load).

              You can't (and don't need to) use an asp:Button control for this. It
              will be client side function only, so you shouldn't need to use a
              server-side control. Just use a normal HTML button or link.

              ie
              <input type=button onclick="window .open();" value="Click Me" />

              The onclick event of an asp:Button control is code to be executed on the
              server in VB or C# etc... The onclick event of a normal HTML button is
              javascript to be run locally within the browser.

              Hope this makes sense!

              Nick...

              Comment

              Working...