1

我在我的网站上使用 ajax 日历扩展器。

 <table border="0" cellpadding="0" cellspacing="0">
                                        <tr>
                                            <td>Active From: <asp:TextBox ID="inputActiveFromDate" runat="server"></asp:TextBox> 
                                                <cc1:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="inputActiveFromDate" PopupButtonID="btn_Calendar1"   Format="dd/MM/yyyy 00:00:00"></cc1:CalendarExtender>
                                                <asp:ImageButton runat="server" ID="btn_Calendar1" ImageUrl="../images/buttons/Lock_icon.gif" />
                                            </td>
                                            <td width="20"></td>
                                            <td>Active Until: <asp:TextBox ID="inputActiveUntilDate" runat="server"></asp:TextBox>
                                                <cc1:CalendarExtender ID="CalendarExtender2" runat="server" TargetControlID="inputActiveUntilDate"  PopupButtonID="btn_Calendar2"  Format="dd/MM/yyyy 23:59:59"></cc1:CalendarExtender>
                                                <asp:ImageButton runat="server" ID="btn_Calendar2" ImageUrl="../images/buttons/Lock_icon.gif" />
                                            </td>
                                        </tr>
                    </table>

一切正常,但我在所有浏览器上都收到此错误。

> Unable to set value of the property 'PopupBehavior': object is null or
> undefined

请帮我解决

错误来了

// Name:        MicrosoftAjax.debug.js
// Assembly:    AjaxControlToolkit
// Version:     4.1.50508.0
// FileVersion: 4.1.50508
// (c) 2010 CodePlex Foundation

initialize: function Behavior$initialize() {
        Sys.UI.Behavior.callBaseMethod(this, 'initialize');
        var name = this.get_name();
        if (name) this._element[name] = this;// error place <---
    },

我的 CS 代码:

using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DBConn"].ToString())){

String  sql = "INSERT INTO tablename (SDate,EDate) VALUES ('" + Convert.ToDateTime(inputActiveFromDate.Text) + "','" + Convert.ToDateTime(inputActiveUntilDate.Text) + "'); SELECT  @@IDENTITY;";conn.Open();
                    SqlCommand comm = new SqlCommand(sql, conn);    
                    comm.ExecuteNonQuery();
                   // int lastId = Convert.ToInt32(comm.ExecuteScalar());
                    conn.Close();




                }
4

1 回答 1

0

我相信问题是因为您使用 PopupButtonID 选项并传入文本框 id

您要么需要删除此选项,要么传入实际按钮的 id

<asp:TextBox ID="inputActiveUntilDate" runat="server"></asp:TextBox>
<cc1:CalendarExtender ID="CalendarExtender2" runat="server" TargetControlID="inputActiveUntilDate" Format="dd/MM/yyyy 23:59:59"></cc1:CalendarExtender>

或者

<asp:TextBox ID="inputActiveUntilDate" runat="server"></asp:TextBox>
<cc1:CalendarExtender ID="CalendarExtender2" runat="server" TargetControlID="inputActiveUntilDate" PopupButtonID="btn_Calendar" Format="dd/MM/yyyy 23:59:59"></cc1:CalendarExtender>
<asp:ImageButton runat="server" ID="btn_Calendar" ImageUrl="PathToACalendarButton" />

编辑:

我不太了解 sql 注入风险,但在我看来,在您的代码中绝对有可能。您可能需要考虑使用参数化查询,例如存储过程。

于 2012-05-01T01:39:24.810 回答