Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/422.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# _C#_Javascript_Asp.net_Ajax - Fatal编程技术网

C#

C# ,c#,javascript,asp.net,ajax,C#,Javascript,Asp.net,Ajax,如果我使用frm.Controls.Add(tblOne)而不是frm.Controls.Add(divContent),那么它可以正常工作,因为tblOne没有Ajax控件。但是divContent既有表也有Ajax控件,它抛出上述异常。我尝试了很多选项,比如覆盖OnInit和OnPreRender,但对我来说不起作用 这可能是由于在代码中放置了ToolkitScriptManager。看看这是否解决了您的问题: 最后,我通过使用JavaScript代码解决了这个问题&对我来说效果更好,我要感


如果我使用
frm.Controls.Add(tblOne)
而不是
frm.Controls.Add(divContent)
,那么它可以正常工作,因为
tblOne
没有Ajax控件。但是
divContent
既有表也有Ajax控件,它抛出上述异常。我尝试了很多选项,比如覆盖
OnInit
OnPreRender
,但对我来说不起作用

这可能是由于在代码中放置了ToolkitScriptManager。看看这是否解决了您的问题:

最后,我通过使用JavaScript代码解决了这个问题&对我来说效果更好,我要感谢所有给我宝贵时间和反馈的人。 代码如下:

<script>
    function Panel1() {
        var panel = document.getElementById("<%=printablediv.ClientID %>");
        var printWindow = window.open('', '', 'height=400,width=800');
        printWindow.document.write('<html><head><title>newTable</title>');

        printWindow.document.write('</head><body >');
        printWindow.document.write(panel.innerHTML);
        printWindow.document.write('</body></html>');
        printWindow.document.close();
        setTimeout(function() {
            printWindow.print();

            printWindow.close();
        }, 1000);
        return false;

    }
    </script>

功能面板1(){
var panel=document.getElementById(“”);
var printWindow=window.open(“”,’高度=400,宽度=800’);
printWindow.document.write('newTable');
printWindow.document.write(“”);
printWindow.document.write(panel.innerHTML);
printWindow.document.write(“”);
printWindow.document.close();
setTimeout(函数(){
printWindow.print();
printWindow.close();
}, 1000);
返回false;
}

您的ASPX页面上的代码是什么?与主题无关,但在javascript中不能有两个同名函数。事实上,也许你可以,但不可预测会调用哪一个。@Nate Kerkhofs先生,如果问题是函数的bcz,那么在使用时会出现错误,我已经重命名了两个函数名,但问题仍然存在。我没有说你的问题是因为函数名,我只是给出了一些与您的代码相关的建议,这些建议与问题无关。这就是为什么我没有把它作为一个答案,因为它不会解决你的问题。不过,这可以防止将来javascript出现潜在问题。非常感谢您的建议,我有点困惑,很抱歉,只是一种预感,但是您可以尝试在控件的onInit事件上注册此事件吗-
<%@ Page Title="" Language="C#" MasterPageFile="~/Masters/TSAMaster.master"      AutoEventWireup="true"
EnableEventValidation="false" Theme="skinFiles" CodeFile="AdminHome.aspx.cs"
Inherits="Masters_Default" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">

<script type="text/javascript">
    function ValidateDate() {
        isValidDate = ValidateDate();
        if (!isValidDate) {
            return false;
        }
        else {
            return true;
        }

    }
    function ValidateDate() {
        var Fdate = document.getElementById('ctl00_ContentPlaceHolder1_txtFDate').value;
        var Tdate = document.getElementById('ctl00_ContentPlaceHolder1_txtTDate').value;

        var todaysDate = formatDate(new Date(), 'dd/MM/yyyy');
        var isValidDate = true;
        var flag;

        if (trim(Fdate) != 0 || trim(Tdate) != 0) {

            if (!isDate(Fdate, 'dd/MM/yyyy')) {
                alert("Please select valid From Date enter into (dd/MM/yyyy) format");
                document.getElementById('ctl00_ContentPlaceHolder1_txtFDate').focus();
                return false;
            }
            if (!isDate(Tdate, 'dd/MM/yyyy')) {
                alert("Please select valid To Date enter into (dd/MM/yyyy) format ");
                document.getElementById('ctl00_ContentPlaceHolder1_txtFDate').focus();
                return false;
            }

            if (((compareDates(Fdate, 'dd/MM/yyyy', Tdate, 'dd/MM/yyyy')) == 1)) {
                alert("To date cannot be less than From Date ");
                return false;
            }
            return true;
        }
    }
    function trim(str) {
        return str.replace(/^[\s]+/, '').replace(/[\s]+$/, '').replace(/[\s]{2,}/, ' ');
    }
</script>

<ajaxToolkit:ToolkitScriptManager runat="Server" EnableScriptGlobalization="true"
    EnableScriptLocalization="true" ID="ScriptManager1" />
<center>
    <div class="divContainPage" id="divContent" runat="server">
        <table id="tblHead" runat="server">
            <tr>
                <td>
                    <asp:Label ID="Label3" runat="server" Text="DueDate Report" Font-Bold="True" Font-Names="Verdana"
                        Font-Size="Large" ForeColor="#C80000"></asp:Label>
                    &nbsp;<br />
                    <br />
                    <table id="tbl1" runat="server" style="width: 823px">
                        <tr>
                            <td>
                                Select Payment Mode:
                            </td>
                            <td>
                                <asp:DropDownList ID="ddlPayMode" runat="server" CssClass="DropDown" Width="85px">
                                    <asp:ListItem>--Select--</asp:ListItem>
                                    <asp:ListItem>Cash</asp:ListItem>
                                    <asp:ListItem>Cheque</asp:ListItem>
                                </asp:DropDownList>
                            </td>
                            <td>
                                From Date:
                            </td>
                            <td>
                                <asp:TextBox ID="txtFDate" runat="server" Width="110px"></asp:TextBox>
                                <asp:ImageButton ID="imgCalendar" runat="server" ImageUrl="~/Images/calendar.png"
                                    TabIndex="1" />
                                <ajaxToolkit:CalendarExtender ID="CalendarExtender2" runat="server" TargetControlID="txtFDate"
                                    Format="dd/MM/yyyy" PopupPosition="BottomRight" PopupButtonID="imgCalendar" />
                            </td>
                            <td>
                                To Date:
                            </td>
                            <td>
                                <asp:TextBox ID="txtTDate" runat="server" Width="110px"></asp:TextBox>
                                <asp:ImageButton ID="imgCalendar1" runat="server" ImageUrl="~/Images/calendar.png"
                                    TabIndex="2" />
                                <ajaxToolkit:CalendarExtender ID="CalendarExtender3" runat="server" TargetControlID="txtTDate"
                                    Format="dd/MM/yyyy" PopupPosition="BottomRight" PopupButtonID="imgCalendar1" />
                            </td>
                            <td>
                                <asp:Button ID="btnGo" runat="server" Text="Go" OnClick="btnGo_Click" OnClientClick="return ValidateDate();" />
                            </td>
                            <td>
                                <asp:Button ID="btnReset" runat="server" Text="Reset" OnClick="btnReset_Click" Width="47px" />
                            </td>
                        </tr>
                    </table>
                    <table style="width: 600px" runat="server" id="tblone">
                        <tr>
                            <td>
                                <asp:GridView ID="grdStudentInfo" runat="server" SkinID="Professional" DataKeyNames="StudentID"
                                    Width="800px" AllowSorting="True" AutoGenerateColumns="False" BackColor="#DEBA84"
                                    BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px" CellPadding="3" CellSpacing="2"
                                    OnSorting="grdStudentInfo_sorting" AllowPaging="True" OnPageIndexChanging="grdStudentInfo_PageIndexChanging"
                                    OnRowCommand="grdStudent_RowCommand">
                                    <RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
                                    <Columns>
                                        <asp:BoundField HeaderText="Name" DataField="FirstandLastName" SortExpression="FirstandLastName">
                                            <ItemStyle HorizontalAlign="left" Width="100px" />
                                            <HeaderStyle HorizontalAlign="left" Width="100px" />
                                        </asp:BoundField>
                                        <asp:BoundField HeaderText="Amount Due" DataField="FirstInstallmentFee" SortExpression="FirstInstallmentFee">
                                            <ItemStyle HorizontalAlign="left" Width="100px" />
                                            <HeaderStyle HorizontalAlign="left" Width="100px" />
                                        </asp:BoundField>
                                        <asp:BoundField HeaderText="Payment Mode" DataField="FirstInsMode" SortExpression="FirstInsMode">
                                            <ItemStyle HorizontalAlign="left" Width="100px" />
                                            <HeaderStyle HorizontalAlign="left" Width="100px" />
                                        </asp:BoundField>
                                        <asp:BoundField HeaderText="Bank Name" DataField="FirstBankName" SortExpression="FirstBankName">
                                            <ItemStyle HorizontalAlign="left" Width="200px" />
                                            <HeaderStyle HorizontalAlign="left" Width="200px" />
                                        </asp:BoundField>
                                        <asp:BoundField HeaderText="Cheque Number" DataField="FirstChequeNumber" SortExpression="FirstChequeNumber">
                                            <ItemStyle HorizontalAlign="left" Width="200px" />
                                            <HeaderStyle HorizontalAlign="left" Width="200px" />
                                        </asp:BoundField>
                                        <asp:BoundField HeaderText="Due Date" DataField="FirstInstallmentDate" SortExpression="FirstInstallmentDate">
                                            <ItemStyle HorizontalAlign="left" Width="200px" />
                                            <HeaderStyle HorizontalAlign="left" Width="200px" />
                                        </asp:BoundField>
                                        <asp:TemplateField HeaderText="Edit">
                                            <ItemTemplate>
                                                <asp:LinkButton ID="lnkEdit" runat="server" CommandName="editStudent" Text="Edit"
                                                    CommandArgument='<%#Eval("StudentID")%>'></asp:LinkButton>
                                            </ItemTemplate>
                                            <ItemStyle HorizontalAlign="Left" Width="200px" />
                                            <HeaderStyle HorizontalAlign="Left" Width="200px" />
                                        </asp:TemplateField>
                                    </Columns>
                                    <FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
                                    <PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
                                    <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
                                    <HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
                                </asp:GridView>
                            </td>
                        </tr>
                    </table>
                    <table id="tbl3" runat="server">
                        <tr style="height: 30px;">
                            <td>
                                <asp:Button ID="btnExport2PDF" runat="server" Text="Export To PDF" OnClick="btnExport2PDF_Click" />
                            </td>
                            <td>
                                <asp:Button ID="btnExport2XLS" runat="server" Text="Export To XLS" OnClick="btnExport2XLS_Click" />
                                <asp:HiddenField ID="hidSort" runat="server" Value="1" />
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
    </div>
</center>
<script>
    function Panel1() {
        var panel = document.getElementById("<%=printablediv.ClientID %>");
        var printWindow = window.open('', '', 'height=400,width=800');
        printWindow.document.write('<html><head><title>newTable</title>');

        printWindow.document.write('</head><body >');
        printWindow.document.write(panel.innerHTML);
        printWindow.document.write('</body></html>');
        printWindow.document.close();
        setTimeout(function() {
            printWindow.print();

            printWindow.close();
        }, 1000);
        return false;

    }
    </script>