Stop javascript from executing on page load and execute from ASP.NET codebehind

Jon Roar Odden

First; I'm trying to do two things in my ASP.NET / JavaScript code.

1) open a jQuery dialog from ASP.NET codebehind. (Works only when the javascript also executes on startup)

2) stop the same javascript/jQuery dialog as mention in 1) from showing on every pageload.

So the code below works great, but executes on page load which I try to stop. In addition this format (without function name) won't let me call the function from codebehind if I understand this How can I prevent this jQuery function from being executed on every page load? correctly:

$(function() {
        $( "#dialogConfirm" ).dialog({
            resizable: false,
            height:180,
            width: 500,
            modal: true,
            buttons: {
                "Delete": function() {
                    $( this ).dialog( "close" );
                },
                "Cancel": function() {
                    $( this ).dialog( "close" );
                }
            }
        });
    });

and this doesn't work (just shows the div on the page and not as a jQuery dialog):

$(function showConfirmDialog() {
        $( "#dialogConfirm" ).dialog({
            resizable: false,
            height:180,
            width: 500,
            modal: true,
            buttons: {
                "Delete": function() {
                    $( this ).dialog( "close" );
                },
                "Cancel": function() {
                    $( this ).dialog( "close" );
                }
            }
        });
    });

The only difference is the lack of function naming in the first. So, can anyone point me in the right direction as to how to just make a script that I can call from codebehind that won't execute on page load?

Kieran Quinn

Change your js function to this:

function ShowDialog() {
    $( "#dialogConfirm" ).dialog({
        resizable: false,
        height:180,
        width: 500,
        modal: true,
        buttons: {
            "Delete": function() {
                $( this ).dialog( "close" );
            },
            "Cancel": function() {
                $( this ).dialog( "close" );
            }
        }
    });
}

Then in your .cs file, put this in the Page_Load

if (IsCallback)
{
    ClientScript.RegisterStartupScript(GetType(), "Javascript", "javascript:ShowDialog();", true);
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Stop javascript from executing on page load and execute from ASP.NET codebehind

From Dev

execute javascript from codebehind in asp.net

From Dev

How to call a codebehind function from javascript in asp.net?

From Dev

returning false from JavaScript Does not stop the HTML page from Executing

From Dev

Asp.net how can I send a list from codebehind to javascript for displaying coordinates in googlemap

From Dev

asp.net Run Javascript confirm from codebehind with custom text and return if OK selected

From Dev

Submit POST request from codebehind in ASP.NET

From Dev

Submit POST request from codebehind in ASP.NET

From Dev

Call Javascript function from codebehind using vb.net

From Dev

Stop executing main application directly and execute it from the second application?

From Dev

Stop page from refreshing in Javascript

From Dev

execute javascript from middle of asp.net button click procedure

From Dev

Calling server-side C# function from either javascript or codebehind c# function ASP.NET

From Dev

call javascript method from codebehind

From Dev

pass the values from javascript to Codebehind

From Dev

How to stop Jquery executing on page load

From Dev

Having trouble geting data from asp.net table from codebehind

From Dev

Having trouble geting data from asp.net table from codebehind

From Dev

Redirect from asp.net page to another using javascript function

From Dev

Stop asp.net from escaping HTML

From Dev

How to automatically execute a javascript function from an external js file on page load with a specific condition

From Dev

How to automatically execute a javascript function from an external js file on page load with a specific condition

From Dev

Execute batch from asp.net hangs

From Dev

how to stop handler from executing

From Dev

how can I get html attribute from ASP/vb.net Codebehind

From Dev

How to pass the SelectedValue from a DropDownList as a query string in a LinkButton with/without using CodeBehind in ASP.net C#

From Dev

how can I get html attribute from ASP/vb.net Codebehind

From Dev

Read text from textarea/textbox in HTML into C# codebehind. (ASP.NET)

From Dev

Asp.net getting label value from codebehind. for google maps coordinate

Related Related

  1. 1

    Stop javascript from executing on page load and execute from ASP.NET codebehind

  2. 2

    execute javascript from codebehind in asp.net

  3. 3

    How to call a codebehind function from javascript in asp.net?

  4. 4

    returning false from JavaScript Does not stop the HTML page from Executing

  5. 5

    Asp.net how can I send a list from codebehind to javascript for displaying coordinates in googlemap

  6. 6

    asp.net Run Javascript confirm from codebehind with custom text and return if OK selected

  7. 7

    Submit POST request from codebehind in ASP.NET

  8. 8

    Submit POST request from codebehind in ASP.NET

  9. 9

    Call Javascript function from codebehind using vb.net

  10. 10

    Stop executing main application directly and execute it from the second application?

  11. 11

    Stop page from refreshing in Javascript

  12. 12

    execute javascript from middle of asp.net button click procedure

  13. 13

    Calling server-side C# function from either javascript or codebehind c# function ASP.NET

  14. 14

    call javascript method from codebehind

  15. 15

    pass the values from javascript to Codebehind

  16. 16

    How to stop Jquery executing on page load

  17. 17

    Having trouble geting data from asp.net table from codebehind

  18. 18

    Having trouble geting data from asp.net table from codebehind

  19. 19

    Redirect from asp.net page to another using javascript function

  20. 20

    Stop asp.net from escaping HTML

  21. 21

    How to automatically execute a javascript function from an external js file on page load with a specific condition

  22. 22

    How to automatically execute a javascript function from an external js file on page load with a specific condition

  23. 23

    Execute batch from asp.net hangs

  24. 24

    how to stop handler from executing

  25. 25

    how can I get html attribute from ASP/vb.net Codebehind

  26. 26

    How to pass the SelectedValue from a DropDownList as a query string in a LinkButton with/without using CodeBehind in ASP.net C#

  27. 27

    how can I get html attribute from ASP/vb.net Codebehind

  28. 28

    Read text from textarea/textbox in HTML into C# codebehind. (ASP.NET)

  29. 29

    Asp.net getting label value from codebehind. for google maps coordinate

HotTag

Archive