locked
Message.Show using jquery and C# RRS feed

  • Question

  • User1224379429 posted

    Hi

    I want to display jquery dialog box from server side using the below code 

    MessageBox.Show("Titlte", "Message goes here");

    I don't want to write jquery code on every page to display dialog. I want to have common code through out the application for displaying the modal dialog.

    How?

    Thanks

    Monday, March 14, 2016 8:27 AM

Answers

  • User475983607 posted

    I have many examples like the one you sent. I want to have a common code, I don't want write the below code in all the aspx pages.

    Copy the code to a js file and reference the js file in a site master page.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, March 14, 2016 12:30 PM
  • User61956409 posted

    Hi mgebhard,

    I agree with mgebhard, you could create a js file and copy your code in this js file, then you could add reference to it in your web page and call this “AlertMsg” function on client side event or another function. Besides, it seems that you are using jQuery plugin, you also need to add reference to required jQuery files.

    Best Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, March 15, 2016 2:10 AM
  • User-1768369891 posted

    I have many examples like the one you sent. I want to have a common code, I don't want write the below code in all the aspx pages.

    Did you have any master pages in your application, if yes then declare your js function on master page and you can call js function directly on page where you want,

    if you want to call js function from server side then check this thread or explain your problem in detail. 

    http://www.aspsnippets.com/Articles/Call-JavaScript-function-from-Code-Behind-Server-Side-in-ASPNet-using-C-and-VBNet.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, March 15, 2016 4:35 AM

All replies

  • User1224379429 posted

    HI @navneet

    I have many examples like the one you sent. I want to have a common code, I don't want write the below code in all the aspx pages.

     <script type="text/javascript">
            function AlertMsg() {
                $("#dialog-Alert").dialog({
                    hide: 'explode',
                    modal: 'true',
                    title: 'Title goes here',
                    draggable: false,
                    resizable: false,
                    height: 150,
                    width: 500,
                    buttons: {
                        Ok: function () {
                            $(this).dialog("close");
                        }
                    }
                });
            }
        </script>

    Monday, March 14, 2016 8:37 AM
  • User475983607 posted

    I have many examples like the one you sent. I want to have a common code, I don't want write the below code in all the aspx pages.

    Copy the code to a js file and reference the js file in a site master page.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, March 14, 2016 12:30 PM
  • User61956409 posted

    Hi mgebhard,

    I agree with mgebhard, you could create a js file and copy your code in this js file, then you could add reference to it in your web page and call this “AlertMsg” function on client side event or another function. Besides, it seems that you are using jQuery plugin, you also need to add reference to required jQuery files.

    Best Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, March 15, 2016 2:10 AM
  • User-1768369891 posted

    I have many examples like the one you sent. I want to have a common code, I don't want write the below code in all the aspx pages.

    Did you have any master pages in your application, if yes then declare your js function on master page and you can call js function directly on page where you want,

    if you want to call js function from server side then check this thread or explain your problem in detail. 

    http://www.aspsnippets.com/Articles/Call-JavaScript-function-from-Code-Behind-Server-Side-in-ASPNet-using-C-and-VBNet.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, March 15, 2016 4:35 AM