我在我的网站上使用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 <---
},
MY CS CODE:
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();
}
答案 0 :(得分: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>
OR
<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注入风险,但在我看来,它肯定可以在你的代码中。您可能想要考虑使用参数化查询,例如存储过程。