0

Ok, I've got a lightbox with a small form (2 fields) in it, inside an UpdatePanel, and I want to close this lightbox (must be done via javascript) when the 'Save' button is pressed.

However, there is a need to have a server-side CustomValidator on the page, and I only want to close the lightbox if this returns as valid.

Does anyone know a way to trigger javascript (or jQuery) code from a server-side validator?

2 Answers 2

2

You can add a little snippet of code using the ScriptManager to execute after the response comes back to the UpdatePanel.

if (Page.IsValid){

   ScriptManager.RegisterStartupScript(
            customValidator1, 
            typeof(MyPageClass), 
            "closeBox",
            "myLightBoxVariableOnThePage.close()",
            true);
}
Sign up to request clarification or add additional context in comments.

Comments

0

When that server side validator runs, it will send a whole new page to the browser. Anything that was shown in the browser before was destroyed, including any state kept in your javascript. If new page bears a strong resemblance to the old page, you should consider this a happy coincidence.

Therefore, the thing to do here is rather than executing a javascript function, have your CustomValidator make the correct changes to the page on success so that it's rendered to the browser correctly in the first place.

1 Comment

Unfortunately, the lightbox simply will not work like that, it's a jQuery lightbox (built on top of FaceBox) which cannot be left open after a postback without removing it from the updatepanel context. It's complex, hence my need to run some javascript code when valid, as opposed to just making the lightbox invisible or something.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.