Sys.Application.add_load Problem with Modal popup extender

I have a current problem, let me explain the context earlier:

I have a modal popup extender that contains a form. There is a β€œSave and add new” function, when the user clicks on this button, the data in the form is saved in the database during postback, and the page reloads.

I want this Modal popup to appear again on the load page, allowing the user to enter new data without having to click again the button that displays this Modal Popup.

I tried calling it as follows:

ClientScript.RegisterStartupScript(Page.GetType(), "ModalPopup", "ShowModalPopup(""" & Me.formModalButton.ID & """);", True)

but the problem was that the function was called by my Modal Popup does not yet exist on the page. Because of this, the code on

var modal = $find('myModal');

So, I found it in a different way and works almost fine .

ClientScript.RegisterStartupScript(Page.GetType(), "ModalPopup", "Sys.Application.add_load(function() {ShowModalPopup(""" & Me.formModalButton.ID & """)};", True)

, , , , .

: Modal Popup , , , .

- , ?

P.S. Modal popup server-side, javascript , RegisterStartupScript.

.

+3
2

, .

ClientScript.Resgister [...], OnClientClick Javascript .

, " ", , "", , .

, - , , Modal Popup Extender .

, , Opera Safari, (Ajax Control toolkit - Modal popup extender).

, IE. , FF Chrome .

ClientScript.RegisterStartupScript(Page.GetType(), "ModalPopup", "Sys.Application.add_load(function() {ShowAddModalPopup(""" & Me.imgAdd.ID & """)});", True)
                btnCancel.OnClientClick = "resetDefaultValue();__doPostBack('" & btnCancel.ID & "','onclick')"

, , FF ,

Sys.WebForms.PageRequestManagerServerErrorException: . , , : 0

workarounf , , ...

ClientScript.RegisterStartupScript(Page.GetType(), "WorkAroundFF", "Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequest); function endRequest(sender, args) { /* Check to see if there an error on this request.*/ if (args.get_error() != undefined) { $get('Error').style.visibility = ""visible""; /* Let the framework know that the error is handled, so it doesn't throw the JavaScript*/ alert. args.set_errorHandled(true); } }", True)

, , , , .

, - .

+2

//Declares gloabal variable
ClientScript.RegisterStartupScript(Page.GetType(),"vardeclaration","var reloadModal;",true);

ClientScript.RegisterStartupScript(Page.GetType(), "ModalPopup", "Sys.Application.add_load(

function() 
{
   reloadModal = function() {ShowAddModalPopup(""" & Me.imgAdd.ID & """);};
   Sys.Application.add_init(reloadModal);
}
);", True)

function cancelClick()
{
   Sys.application.remove_init(reloadModal);
}
+2

Source: https://habr.com/ru/post/1703113/


All Articles