开发者

How to make the content of the popup make a PostBack only when it's appeared

I have a user control is shown through a SimpleModal popup (JQuery), this user control gets some data from database and displays them (the details of a record).

The problem is that this user control makes a round-trip to gets the data every PostBack for the parent page even it's hidden.

I wonder if I could make it gets its data only if the popup is appeared.

I tried to put it inside a Panel with false for Visible property and开发者_如何学运维 change it to true when I open the popup, but it stil call Page_Load which gets the data from database!

Any idea !!


There are several approaches to tackle it.

1.Do everything on the server side. You can use the ajax (former atlas) toolkit's modal dilog. Put it inside an update panel. Create a trigger and specify the event in that trigger - that will be when you will do the call to the db. It will only happen once and you will have control over when exactly you want to do it.

2. Use client side ajax. I favor this way as there is a lot of overhead associated with using the UpdatePanel (performance). Keep the jQuery UI Modal Dialog in tact, use the client side event to hook to it when it's opened. Then you would have to either do a .ajax call to a webservice (can be hosted within an aspx page) or you can do a .get:

    $.ajax({
      url: url,
      data: data,
      success: success,
      dataType: dataType
    });

or

   $.get('ajax/MyDbRecord.aspx', function(data) {
       $('.result').html(data);
        alert('Load was performed.');
   });

Then your aspx page can simply:

Response.Write(MyRepository.GetDetail(q=>q.ID == 1234).ToString()); Resonse.End();

That is of course, if you only need to display that data in your modal dialog as a simple string and won't need to examine your object on the business side.

Both api's described here in detail: http://api.jquery.com/jQuery.get/

Now if you actually want to do something custom with the detail record you are retrieving from the db, you might want to look into using the getJSON. More examples here:

http://viralpatel.net/blogs/2009/04/jquery-ajax-tutorial-example-ajax-jquery-development.html


Fire an ajax request when the user activate the popup and fill the pop up with values retrieved from the request.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜