Click here to Skip to main content
15,895,667 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
From script tag

C#
$('input[id*=anyTrouble]').click(function () {
    alert('trouble has arrived');
    var con = $('#myTroubleNote').val();
    $("#troubleNote").val(con);
    $("#dialog-trouble").dialog("open");
    return false;
});

C#
$("#dialog-trouble").dialog({
    title: "Trouble Information",
    autoOpen: false,
    height: 600,
    width: 1000,
    modal: true,
    dialogClass: "no-close",
    buttons: {
        "Okay": {
            class: 'okDialogButton',
            text: 'OK',
            click: function () {
                var bValid = true;
                var tType = $("#ddl_TType option:selected").val();
                var tModule = $("#ddl_Module option:selected").val();
                var thisNote = $('#troubleNote');
                var notelength = thisNote.val();

                bValid = bValid && checkLength(thisNote, "TroubleNote", 3, 2048);
                bValid = bValid && (notelength.length > 2);
                /* here is where you put the content of the note into the hidden variable.*/
                if (bValid) {
                    $('#myTroubleNote').val(thisNote.val());
                    $('#myTroubleNote').change();
                    $('#myType').val(tType);
                    $('#myType').change();
                    $('#myModule').val(tModule);
                    $('#myModule').change();
                    $(this).dialog("close");
                }
            }
        },
        Cancel: function () {
            $(this).dialog("close");
        }
    },
    close: function () {
        allFields.val("").removeClass("ui-state-error");
    }
});



From body tag

<asp:Button ID="anyTrouble" name="anyTrouble" runat="server" Text="Report Error/Request" CssClass="annbutton" />


XML
<div id="dialog-trouble" style="display:none;" >
            <asp:Label ID="lbl_TType" runat="server" style="position:absolute; left: 40px; top: 5px; background-color:inherit; font-size:small; font-names:Cambria,small;" Visible="true" >Type of Problem/Request:</asp:Label>
            <asp:DropDownList ID="ddl_TType" runat="server" ClientIDMode="Static"
                style="position:absolute; left: 220px; top: 5px; background-color:inherit; font-size:small; font-names:Cambria,small; width: 265px;" visible="true">
            </asp:DropDownList>
            <asp:Label ID="lbl_Module" runat="server"
                style="position:absolute; left: 590px; top: 5px; background-color:inherit; font-size:small; width: 114px; font-names:Cambria,small; right: 444px;"
                Visible="true" >Module or Page :</asp:Label>
            <asp:DropDownList ID="ddl_Module" runat="server" ClientIDMode="Static"
                style="position:absolute; left: 710px; top: 5px; background-color:inherit; font-size:small; font-names:Cambria,small; width: 225px;" visible="true">
            </asp:DropDownList>
            <asp:TextBox ID="troubleNote" runat="server" BackColor="#F0F0F0" Visible="true" ClientIDMode="Static"
                BorderColor="#669999" BorderStyle="Solid" BorderWidth="2px"
                Font-Names="Cambria" Font-Size="Medium" ForeColor="Black" Rows="40"
                Wrap="true" Text="" style="position:absolute; top: 25px; left: 40px; height: 600px; width: 1000px;" TextMode="MultiLine">
            </asp:TextBox>
</div>
Posted
Comments
Afzaal Ahmad Zeeshan 26-Aug-15 19:00pm    
What is the error code that you get?
Member 11571088 26-Aug-15 19:09pm    
There is no error code. The code actually goes through the script that calls the dialog.("open"), but the "open" is never executed.
Afzaal Ahmad Zeeshan 26-Aug-15 19:17pm    
Console has the error that was raised, please open the console and see it. Press F12.
Member 11571088 27-Aug-15 11:04am    
the error text is:

cannot call methods on dialog prior to initialization; attempted to call method 'open'.

jQuery version 1.9.1; jQuery UI version 1.10.3

I am setting the dialog options in a local javascript library and it looks like this:

$("#dialog-trouble").dialog({
title: "Trouble Information",
autoOpen: false,
height: 600,
width: 1000,
modal: true,
dialogClass: "no-close",
buttons: {
"Okay": {
class: 'okDialogButton',
text: 'OK',
click: function () {
var bValid = true;
var tType = $("#ddl_TType option:selected").val();
var tModule = $("#ddl_Module option:selected").val();
var thisNote = $('#troubleNote');
var notelength = thisNote.val();

bValid = bValid && checkLength(thisNote, "TroubleNote", 3, 2048);
bValid = bValid && (notelength.length > 2);
/* here is where you put the content of the note into the hidden variable.*/
if (bValid) {
$('#myTroubleNote').val(thisNote.val());
$('#myTroubleNote').change();
$('#myType').val(tType);
$('#myType').change();
$('#myModule').val(tModule);
$('#myModule').change();
$(this).dialog("close");
}
}
},
Cancel: function () {
$(this).dialog("close");
}
},
close: function () {
allFields.val("").removeClass("ui-state-error");
}
});


I did modify the original .dialog("open") call to .dialog({ autoOpen: false }).dialog("open") just to initialize the dialog before opening. That seems to work, somewhat. Now my Okay and Cancel buttons are not appearing and the dialog window is not picking up the size options in the open call.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900