6

I have a div that is shown as a Modal dialog.

<div id="div2" style="display: none;" title="Upload Prenda">
        <center>
            <br />
            Select File to Upload:
            <asp:FileUpload ID="PrendaFileUpload" runat="server" Width="345px" />
            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="PrendaFileUpload"
                ErrorMessage="File to be uploaded Required" ValidationGroup="X">*</asp:RequiredFieldValidator><br />
            <asp:ValidationSummary ID="ValidationSummary1" runat="server" ShowMessageBox="True"
                ShowSummary="False" ValidationGroup="X" />
            <br />
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
            <asp:Button ID="uploadButton" runat="server" Text="Upload" OnClick="uploadButton_Click"
                 Width="100px" />
        </center>
    </div>

here is the jquery for it

 <script type="text/javascript">
$(function() {
$( "#div2" ).dialog({
autoOpen: false,
modal:true,
resizable: false,
 height: 200,
width: 600
});
$( "#toggle" ).click(function() {
$( "#div2" ).dialog( "open" );
});
});
</script> 

the problem is after i press the button to activate the OnClick="uploadButton_Click" the method inside does not fire, any fix for this? sorry im just new in using jquery.

Albert Laure
  • 1,702
  • 5
  • 20
  • 49
  • 1
    I think you will find that the problem is that jQuery dialogs are done is such a way that removes them from the normal ASP.NET form tags. I had this problem about a year ago and can't remember exactly what I did, or where I found the answer. Pretty sure it was on this site somewhere. If I can find it I will update this with a link to the answer. There was a pretty simple fix, it's just tricky to find. – Tyler Durden Nov 21 '13 at 03:57

4 Answers4

15

Well this is the answer that worked for me, im not using any update panel and this is what i used

adding this to the dialog declaration:

  open: function(type,data) {
    $(this).parent().appendTo("form");
  }

found the answer in here so if you want to know more about click the link beside :)

Community
  • 1
  • 1
Albert Laure
  • 1,702
  • 5
  • 20
  • 49
3

The newer versions of JQueryUI use a slightly different convention. In your .dialog() declaration, add this is a parameter:

appendTo: "form",

This fixes the issue for new versions of JQuery, since it builds the dialog box outside the scope of the ASP.NET form. Hope this helps newer users!

Daniel Anderson
  • 275
  • 3
  • 16
1

Try this solution: jQuery modal dialog with postbacks in ASP.NET

This tells jQuery to append the dialog to the form tag rather than the end of the document.

Community
  • 1
  • 1
Tyler Durden
  • 1,016
  • 15
  • 24
1

This query will fire C# code from JQuery. I tested it:

 $(this).parent().appendTo($("form:first"));
Box Box Box Box
  • 5,094
  • 10
  • 49
  • 67