开发者

How do you modify a modal popup from ASP codebehind instead of letting it close?

I'm using SimpleModal to create a popup on an ASP.net application. The OK button calls a server-side function - and based on the resulta of that function I'd like to modify the popup (make some things visible, etc.) instead of letting it close. If that's too difficult, I'd like to open the popup again without the user having to re-click on anything. 开发者_StackOverflowI'm just not sure what the best way to do this is.

Currently the OK button in the popup looks like this:

<asp:ImageButton ID="submitInfoBtn" OnClick="btnSubmitInfo_Click"
           ImageUrl="css/assets/btn_ok.png" runat="server"/>  

and there is nothing defined that tells anything that the OK button should close the popup (the Cancel button has class="simplemodal-close", so I would expect it to do just that, but not the OK button) - anyone have any ideas on the best way through this? Thanks in advance!!


You need to set the Javascript handler for the button with return false. See... How to disable postback on an asp Button

Notice the return false. This will prevent a Postback.

Now you can get any server data that you need using Ajax in your Javascript button handler and use JQuery to modify your Popup.

By the way, you can also use JQuery UI Dialog for modal popups. You may have much more support using that.


It's not so difficult, see my code of the pop up window. There is an OK button in the pop up, sometimes clicking OK will modify the pop up window, sometimes clicking will close the window, do I have a misunderstanding?

void OK_click(object sender, EventArgs e)
{
   try
   {
      if (DataIsValid())
      {
        Save();
        this.Page.ClientScript.RegisterStartupScript(typeof(Page), "closeWindow", "<script type='text/javascript'>self.opener=null; self.close();</script>");
      }
      else ErrorLabel.Visible = true;
   }
   catch { ErrorLabel.Visible = true; }

}


You'll want to use the SimpleModal onShow callback to bind to the OK button, make the ajax request, then check the response and show the new content.

You shouldn't use the onClose callback because it's just for animating the close or any cleanup. You can programatically close the dialog when you are ready with $.modal.close();

It will involve checking the dimensions of the returned content and adjusting the modal dimensions accordingly.

Have a look at the flickr badge viewer demo (http://www.ericmmartin.com/projects/simplemodal-demos/) for an example of what I'm talking about.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜