Execute JavaScript from server side

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

    #1

    Execute JavaScript from server side

    I have a HoverMenuExtend er which contains an asp:PlaceHolder , this place
    holder has a User Control and this control contrains a Button.

    The problem I am having is after the button fires the click event I want to
    do a server side function and then refresh the Page where the PlaceHolder
    risides.
    I have no problem doing the server side function, but the following 'alert'
    never shows up after the server side funtion.

    I am using the alert function instead of
    '__doPostBack(d ocument.getElem entById('upRunn ingJobs'), "test");' just for
    testing as simplicity.

    ScriptManager.R egisterStartupS cript(this, GetType(), "Refresh",
    "alert('test'); ", false);


    Here's my button click event:

    protected void butCancel_Click (object sender, EventArgs e)
    {
    RunningJobsCont roller rjc = new RunningJobsCont roller();
    rjc.CancelJob(t his.RReport.Ins tanceID);

    //
    // the alert from the following line never shows up
    //
    ScriptManager.R egisterStartupS cript(this, GetType(), "Refresh",
    "alert('test'); ", false);

    }


    Thank You.


    Peter




  • Mark Rae [MVP]

    #2
    Re: Execute JavaScript from server side

    "Peter" <czupet@nospam. nospamwrote in message
    news:%235vC3QeR JHA.3628@TK2MSF TNGP06.phx.gbl. ..
    //
    // the alert from the following line never shows up
    //
    ScriptManager.R egisterStartupS cript(this, GetType(), "Refresh",
    "alert('test'); ", false);
    Does it work if you change the final argument from false to true...?


    --
    Mark Rae
    ASP.NET MVP


    Comment

    • Peter

      #3
      Re: Execute JavaScript from server side

      No, it does not matter if it's true or false


      "Mark Rae [MVP]" <mark@markNOSPA Mrae.netwrote in message
      news:uqAsezeRJH A.1028@TK2MSFTN GP05.phx.gbl...
      "Peter" <czupet@nospam. nospamwrote in message
      news:%235vC3QeR JHA.3628@TK2MSF TNGP06.phx.gbl. ..
      >
      >//
      >// the alert from the following line never shows up
      >//
      >ScriptManager. RegisterStartup Script(this, GetType(), "Refresh",
      >"alert('test') ;", false);
      >
      Does it work if you change the final argument from false to true...?
      >
      >
      --
      Mark Rae
      ASP.NET MVP
      http://www.markrae.net

      Comment

      • Mark Rae [MVP]

        #4
        Re: Execute JavaScript from server side

        "Peter" <czupet@nospam. nospamwrote in message
        news:%23UeVV6eR JHA.5568@TK2MSF TNGP05.phx.gbl. ..
        >>//
        >>// the alert from the following line never shows up
        >>//
        >>ScriptManager .RegisterStartu pScript(this, GetType(), "Refresh",
        >>"alert('test' );", false);
        >>
        >Does it work if you change the final argument from false to true...?
        >
        No, it does not matter if it's true or false
        If you do a View Source, do you see the JavaScript alert...?


        --
        Mark Rae
        ASP.NET MVP


        Comment

        • Allen Chen [MSFT]

          #5
          Re: Execute JavaScript from server side

          Hi Peter,

          I think it should work if you set the last parameter to true. It looks very
          strange. Could you send me a simple demo that can reproduce this problem?
          I'll troubleshoot on my side to see what the problem is.

          Regards,
          Allen Chen
          Microsoft Online Support

          Delighting our customers is our #1 priority. We welcome your comments and
          suggestions about how we can improve the support we provide to you. Please
          feel free to let my manager know what you think of the level of service
          provided. You can send feedback directly to my manager at:
          msdnmg@microsof t.com.

          =============== =============== =============== =====
          Get notification to my posts through email? Please refer to
          http://msdn.microsoft.com/en-us/subs...#notifications.

          Note: MSDN Managed Newsgroup support offering is for non-urgent issues
          where an initial response from the community or a Microsoft Support
          Engineer within 2 business day is acceptable. Please note that each follow
          up response may take approximately 2 business days as the support
          professional working with you may need further investigation to reach the
          most efficient resolution. The offering is not appropriate for situations
          that require urgent, real-time or phone-based interactions. Issues of this
          nature are best handled working with a dedicated Microsoft Support Engineer
          by contacting Microsoft Customer Support Services (CSS) at
          http://msdn.microsoft.com/en-us/subs.../aa948874.aspx
          =============== =============== =============== =====
          This posting is provided "AS IS" with no warranties, and confers no rights.

          --------------------
          | From: "Peter" <czupet@nospam. nospam>
          | References: <#5vC3QeRJHA.36 28@TK2MSFTNGP06 .phx.gbl>
          <uqAsezeRJHA.10 28@TK2MSFTNGP05 .phx.gbl>
          | Subject: Re: Execute JavaScript from server side
          | Date: Thu, 13 Nov 2008 18:18:54 -0600
          | Lines: 23
          | X-Priority: 3
          | X-MSMail-Priority: Normal
          | X-Newsreader: Microsoft Outlook Express 6.00.2900.5512
          | X-RFC2646: Format=Flowed; Response
          | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579
          | Message-ID: <#UeVV6eRJHA.55 68@TK2MSFTNGP05 .phx.gbl>
          | Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
          | NNTP-Posting-Host: CPE-72-129-145-58.new.res.rr.c om 72.129.145.58
          | Path: TK2MSFTNGHUB02. phx.gbl!TK2MSFT NGP01.phx.gbl!T K2MSFTNGP05.phx .gbl
          | Xref: TK2MSFTNGHUB02. phx.gbl
          microsoft.publi c.dotnet.framew ork.aspnet:7984 5
          | X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
          |
          | No, it does not matter if it's true or false
          |
          |
          | "Mark Rae [MVP]" <mark@markNOSPA Mrae.netwrote in message
          | news:uqAsezeRJH A.1028@TK2MSFTN GP05.phx.gbl...
          | "Peter" <czupet@nospam. nospamwrote in message
          | news:%235vC3QeR JHA.3628@TK2MSF TNGP06.phx.gbl. ..
          | >
          | >//
          | >// the alert from the following line never shows up
          | >//
          | >ScriptManager. RegisterStartup Script(this, GetType(), "Refresh",
          | >"alert('test') ;", false);
          | >
          | Does it work if you change the final argument from false to true...?
          | >
          | >
          | --
          | Mark Rae
          | ASP.NET MVP
          | http://www.markrae.net
          |
          |
          |

          Comment

          • Peter

            #6
            Re: Execute JavaScript from server side

            "Mark Rae [MVP]" <mark@markNOSPA Mrae.netwrote in message
            news:ulyYcFfRJH A.3516@TK2MSFTN GP03.phx.gbl...
            "Peter" <czupet@nospam. nospamwrote in message
            news:%23UeVV6eR JHA.5568@TK2MSF TNGP05.phx.gbl. ..
            >
            >>>//
            >>>// the alert from the following line never shows up
            >>>//
            >>>ScriptManage r.RegisterStart upScript(this, GetType(), "Refresh",
            >>>"alert('test ');", false);
            >>>
            >>Does it work if you change the final argument from false to true...?
            >>
            >No, it does not matter if it's true or false
            >
            If you do a View Source, do you see the JavaScript alert...?
            >
            >
            --
            Mark Rae
            ASP.NET MVP
            http://www.markrae.net
            No I do not

            FYI: This is a DotNetNuke application.


            Comment

            • Allen Chen [MSFT]

              #7
              Re: Execute JavaScript from server side

              Hi Peter,

              Thanks for your code. It's a page life cycle issue. You're dynamically
              creating controls in the ItemDataBound event handler so the click event of
              the button will not fire on postback. To work it around please try
              following steps:

              1. Comment the following lines in the lstContent_Item DataBound event
              handler in the ViewRunningJobs .ascx.cs:
              PopUpData pud
              =(PopUpData)Pag e.LoadControl(" ~/DesktopModules/RunningJobs/PopUpData.ascx" );
              pud.RReport = (RunningReport) e.Item.DataItem ;
              phParameters.Co ntrols.Add(pud) ;
              phParameters.Vi sible = true;

              2. Replace the DataList in ViewRunningJobs .ascx with following one:
              <asp:DataList ID="lstContent " DataKeyField="I temID" runat="server"
              CellPadding="4"
              OnItemDataBound ="lstContent_It emDataBound">
              <ItemTemplate >
              <table cellpadding="4" width="100%">
              <tr>
              <td valign="top" width="100%" align="left">
              <asp:Image ID="imgJob" runat="server"
              ImageUrl="" Height="36px" Width="42px" />
              <asp:HyperLin k ID="HyperLink1 " NavigateUrl='<% #
              EditUrl("ItemID ",((int)DataBin der.Eval(Contai ner.DataItem,"I temID")).ToStri n
              g()) %>'
              Visible="<%# IsEditable %>" runat="server">
              <asp:Image ID="Image1" runat="server"
              ImageUrl="~/images/edit.gif" AlternateText=" Edit"
              Visible="<%# IsEditable%>"
              resourcekey="Ed it" />
              </asp:HyperLink>
              <asp:Label ID="lblContent " Font-Size="12pt"
              ForeColor="Blue " runat="server" />
              --Start Time '<%#
              DataBinder.Eval (Container.Data Item,"StartTime ") %>' <span id="InstanceID "
              style="display: none">Report ID '<%#
              DataBinder.Eval (Container.Data Item, "InstanceID")%> '
              </span>
              <div>
              <cc1:HoverMenuE xtender
              ID="HoverMenuEx tender1" runat="server" TargetControlID ="imgJob"
              PopupControlID= "pnlReportI nfo"
              PopupPosition=" Right" PopDelay="25" OffsetY="-240" OffsetX="-30">
              </cc1:HoverMenuEx tender>
              <asp:Panel ID="pnlReportIn fo" runat="server"
              CssClass="ballo onstyle">
              <br />
              <br />
              <asp:PlaceHolde r ID="phParameter s"
              runat="server">
              <uc1:PopUpDat a runat="server"
              ID="PopUpData1 " Visible="true" /></asp:PlaceHolder >
              <DBWC:DynamicCo ntrolsPlacehold er
              ID="phParameter s1" runat="server">
              </DBWC:DynamicCon trolsPlaceholde r>
              </asp:Panel>
              </div>
              </td>
              </tr>
              </table>
              </ItemTemplate>
              </asp:DataList>

              In this way we add the PopUpData control in aspx directly instead of
              dynamically creating it in the code behind. The control will then be
              populated on an earlier stage of the page life cycle that can make sure the
              event will fire on the postback.
              Please let me know if it works.

              Regards,
              Allen Chen
              Microsoft Online Support

              Delighting our customers is our #1 priority. We welcome your comments and
              suggestions about how we can improve the support we provide to you. Please
              feel free to let my manager know what you think of the level of service
              provided. You can send feedback directly to my manager at:
              msdnmg@microsof t.com.

              =============== =============== =============== =====
              Get notification to my posts through email? Please refer to
              http://msdn.microsoft.com/en-us/subs...#notifications.

              Note: MSDN Managed Newsgroup support offering is for non-urgent issues
              where an initial response from the community or a Microsoft Support
              Engineer within 2 business day is acceptable. Please note that each follow
              up response may take approximately 2 business days as the support
              professional working with you may need further investigation to reach the
              most efficient resolution. The offering is not appropriate for situations
              that require urgent, real-time or phone-based interactions. Issues of this
              nature are best handled working with a dedicated Microsoft Support Engineer
              by contacting Microsoft Customer Support Services (CSS) at
              http://msdn.microsoft.com/en-us/subs.../aa948874.aspx
              =============== =============== =============== =====
              This posting is provided "AS IS" with no warranties, and confers no rights.

              --------------------
              | From: "Peter" <czupet@nospam. nospam>
              | References: <#5vC3QeRJHA.36 28@TK2MSFTNGP06 .phx.gbl>
              <uqAsezeRJHA.10 28@TK2MSFTNGP05 .phx.gbl>
              | Subject: Re: Execute JavaScript from server side
              | Date: Thu, 13 Nov 2008 18:18:54 -0600
              | Lines: 23
              | X-Priority: 3
              | X-MSMail-Priority: Normal
              | X-Newsreader: Microsoft Outlook Express 6.00.2900.5512
              | X-RFC2646: Format=Flowed; Response
              | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579
              | Message-ID: <#UeVV6eRJHA.55 68@TK2MSFTNGP05 .phx.gbl>
              | Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
              | NNTP-Posting-Host: CPE-72-129-145-58.new.res.rr.c om 72.129.145.58
              | Path: TK2MSFTNGHUB02. phx.gbl!TK2MSFT NGP01.phx.gbl!T K2MSFTNGP05.phx .gbl
              | Xref: TK2MSFTNGHUB02. phx.gbl
              microsoft.publi c.dotnet.framew ork.aspnet:7984 5
              | X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
              |
              | No, it does not matter if it's true or false
              |
              |
              | "Mark Rae [MVP]" <mark@markNOSPA Mrae.netwrote in message
              | news:uqAsezeRJH A.1028@TK2MSFTN GP05.phx.gbl...
              | "Peter" <czupet@nospam. nospamwrote in message
              | news:%235vC3QeR JHA.3628@TK2MSF TNGP06.phx.gbl. ..
              | >
              | >//
              | >// the alert from the following line never shows up
              | >//
              | >ScriptManager. RegisterStartup Script(this, GetType(), "Refresh",
              | >"alert('test') ;", false);
              | >
              | Does it work if you change the final argument from false to true...?
              | >
              | >
              | --
              | Mark Rae
              | ASP.NET MVP
              | http://www.markrae.net
              |
              |
              |

              Comment

              • Peter

                #8
                Re: Execute JavaScript from server side

                Thank You for your help

                But the changes did not help, still JavaScript does not execut from the
                button_click event in the User Control.


                "Allen Chen [MSFT]" <v-alchen@online.m icrosoft.comwro te in message
                news:bLOSGRkRJH A.5028@TK2MSFTN GHUB02.phx.gbl. ..
                Hi Peter,
                >
                Thanks for your code. It's a page life cycle issue. You're dynamically
                creating controls in the ItemDataBound event handler so the click event of
                the button will not fire on postback. To work it around please try
                following steps:
                >
                1. Comment the following lines in the lstContent_Item DataBound event
                handler in the ViewRunningJobs .ascx.cs:
                PopUpData pud
                =(PopUpData)Pag e.LoadControl(" ~/DesktopModules/RunningJobs/PopUpData.ascx" );
                pud.RReport = (RunningReport) e.Item.DataItem ;
                phParameters.Co ntrols.Add(pud) ;
                phParameters.Vi sible = true;
                >
                2. Replace the DataList in ViewRunningJobs .ascx with following one:
                <asp:DataList ID="lstContent " DataKeyField="I temID" runat="server"
                CellPadding="4"
                OnItemDataBound ="lstContent_It emDataBound">
                <ItemTemplate >
                <table cellpadding="4" width="100%">
                <tr>
                <td valign="top" width="100%" align="left">
                <asp:Image ID="imgJob" runat="server"
                ImageUrl="" Height="36px" Width="42px" />
                <asp:HyperLin k ID="HyperLink1 " NavigateUrl='<% #
                EditUrl("ItemID ",((int)DataBin der.Eval(Contai ner.DataItem,"I temID")).ToStri n
                g()) %>'
                Visible="<%# IsEditable %>" runat="server">
                <asp:Image ID="Image1" runat="server"
                ImageUrl="~/images/edit.gif" AlternateText=" Edit"
                Visible="<%# IsEditable%>"
                resourcekey="Ed it" />
                </asp:HyperLink>
                <asp:Label ID="lblContent " Font-Size="12pt"
                ForeColor="Blue " runat="server" />
                --Start Time '<%#
                DataBinder.Eval (Container.Data Item,"StartTime ") %>' <span id="InstanceID "
                style="display: none">Report ID '<%#
                DataBinder.Eval (Container.Data Item, "InstanceID")%> '
                </span>
                <div>
                <cc1:HoverMenuE xtender
                ID="HoverMenuEx tender1" runat="server" TargetControlID ="imgJob"
                PopupControlID= "pnlReportI nfo"
                PopupPosition=" Right" PopDelay="25" OffsetY="-240" OffsetX="-30">
                </cc1:HoverMenuEx tender>
                <asp:Panel ID="pnlReportIn fo"
                runat="server"
                CssClass="ballo onstyle">
                <br />
                <br />
                <asp:PlaceHolde r ID="phParameter s"
                runat="server">
                <uc1:PopUpDat a runat="server"
                ID="PopUpData1 " Visible="true" /></asp:PlaceHolder >
                <DBWC:DynamicCo ntrolsPlacehold er
                ID="phParameter s1" runat="server">
                </DBWC:DynamicCon trolsPlaceholde r>
                </asp:Panel>
                </div>
                </td>
                </tr>
                </table>
                </ItemTemplate>
                </asp:DataList>
                >
                In this way we add the PopUpData control in aspx directly instead of
                dynamically creating it in the code behind. The control will then be
                populated on an earlier stage of the page life cycle that can make sure
                the
                event will fire on the postback.
                Please let me know if it works.
                >
                Regards,
                Allen Chen
                Microsoft Online Support
                >
                Delighting our customers is our #1 priority. We welcome your comments and
                suggestions about how we can improve the support we provide to you. Please
                feel free to let my manager know what you think of the level of service
                provided. You can send feedback directly to my manager at:
                msdnmg@microsof t.com.
                >
                =============== =============== =============== =====
                Get notification to my posts through email? Please refer to
                http://msdn.microsoft.com/en-us/subs...#notifications.
                >
                Note: MSDN Managed Newsgroup support offering is for non-urgent issues
                where an initial response from the community or a Microsoft Support
                Engineer within 2 business day is acceptable. Please note that each follow
                up response may take approximately 2 business days as the support
                professional working with you may need further investigation to reach the
                most efficient resolution. The offering is not appropriate for situations
                that require urgent, real-time or phone-based interactions. Issues of this
                nature are best handled working with a dedicated Microsoft Support
                Engineer
                by contacting Microsoft Customer Support Services (CSS) at
                http://msdn.microsoft.com/en-us/subs.../aa948874.aspx
                =============== =============== =============== =====
                This posting is provided "AS IS" with no warranties, and confers no
                rights.
                >
                --------------------
                | From: "Peter" <czupet@nospam. nospam>
                | References: <#5vC3QeRJHA.36 28@TK2MSFTNGP06 .phx.gbl>
                <uqAsezeRJHA.10 28@TK2MSFTNGP05 .phx.gbl>
                | Subject: Re: Execute JavaScript from server side
                | Date: Thu, 13 Nov 2008 18:18:54 -0600
                | Lines: 23
                | X-Priority: 3
                | X-MSMail-Priority: Normal
                | X-Newsreader: Microsoft Outlook Express 6.00.2900.5512
                | X-RFC2646: Format=Flowed; Response
                | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579
                | Message-ID: <#UeVV6eRJHA.55 68@TK2MSFTNGP05 .phx.gbl>
                | Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
                | NNTP-Posting-Host: CPE-72-129-145-58.new.res.rr.c om 72.129.145.58
                | Path: TK2MSFTNGHUB02. phx.gbl!TK2MSFT NGP01.phx.gbl!T K2MSFTNGP05.phx .gbl
                | Xref: TK2MSFTNGHUB02. phx.gbl
                microsoft.publi c.dotnet.framew ork.aspnet:7984 5
                | X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
                |
                | No, it does not matter if it's true or false
                |
                |
                | "Mark Rae [MVP]" <mark@markNOSPA Mrae.netwrote in message
                | news:uqAsezeRJH A.1028@TK2MSFTN GP05.phx.gbl...
                | "Peter" <czupet@nospam. nospamwrote in message
                | news:%235vC3QeR JHA.3628@TK2MSF TNGP06.phx.gbl. ..
                | >
                | >//
                | >// the alert from the following line never shows up
                | >//
                | >ScriptManager. RegisterStartup Script(this, GetType(), "Refresh",
                | >"alert('test') ;", false);
                | >
                | Does it work if you change the final argument from false to true...?
                | >
                | >
                | --
                | Mark Rae
                | ASP.NET MVP
                | http://www.markrae.net
                |
                |
                |
                >

                Comment

                Working...