How asp:button Postback work with JQueryUI Dialog? (Not ASP

How asp:button Postback work with JQueryUI Dialog? (Not ASP

I read http://stackoverflow.com/questions/7572 ... n-postback

The dialog can popup but close itself.

When I click btnBegin asp:button, it will call server side C# code to get data from DB and then assign to label:begin.

In the first time, dialog cannot show the label:begin and then close.
In second time, dialog can show the text in label:begin and then close.

I use JQueryUI Dialog plugin



<script type="text/javascript">
function openModalDiv(divname) {           
        $('#' + divname).dialog({
            autoOpen: false,
            bgiframe: true,
            height: 300,
            modal: true,
            buttons: {            
   'Close': function() {
   $(this).dialog('close');
   }
   }
});         
$('#' + divname).dialog('open');     
$('#' + divname).parent().appendTo($("form:first"));       
}     
   
function closeModalDiv(divname) {           
$('#' + divname).dialog('close');       
}
</script>

<asp:button id="btnBegin" runat="server" Text="Begin" OnClientClick="javascript:openModalDiv('dialogBegin');" ></asp:button>

<div id="dialogBegin" title="Beginning'/>"  >
   <fieldset>
      <asp:Label ID=begin runat=server></asp:Label><br /><br />
      <asp:TextBox ID="beginInput" runat="server" ></asp:TextBox><br />
      <asp:imagebutton id="btnInsert" ImageUrl="insert.gif" runat="server" /><br />
      <asp:Label ID=lblResult runat=server></asp:Label>
   </fieldset>
</div>