我最近在我的页面中添加了一个AjaxToolkit:ScriptManager来使用它们提供的CalenderExtender,因为这样做我的按钮都没有在事件服务器端点击。
我在我的方法上添加了一个断点,并且按钮的相应方法没有被点击,我想知道它是否是因为ScriptManager。
我尝试将UseSubmitBehavior="false"
添加到按钮中,并且窗台不起作用,并且还将EnablePageMethods="true"
添加到ScriptManager。
<ajaxToolkit:ToolkitScriptManager ID="sct1" runat="server" EnablePageMethods="true"></ajaxToolkit:ToolkitScriptManager>
以下是一个示例按钮:
<asp:UpdatePanel ID="AddDepartments" runat="server" class="AddDepartments">
<ContentTemplate>
<asp:Label ID="lbl_adddepartmentadmin" runat="server" Text="Add Department:" CssClass="applicationfont" />
<input id="txt_adddepartmentadmin" runat="server" type="text" class="smallinputbox" />
<asp:Button id="btn_adddepartmentadmin" runat="server" CssClass="Button" Text="Add" OnClick="btn_adddepartmentadmin_Click" UseSubmitBehavior="false" />
</ContentTemplate>
</asp:UpdatePanel>
事件背后的代码:
protected void btn_adddepartmentadmin_Click(object sender, EventArgs e)
{
if (txt_adddepartmentadmin.Value == "" || txt_adddepartmentadmin.Value == null)
{
ScriptManager.RegisterStartupScript(this, typeof(string), "Error", "alert('Please enter a valid department name.');", true);
}
else
{
string returnResult = wsP.AddDepartment(new wsPersonnel.DC_LIST_DEPARTMENTS { DEPARTMENT_NAME = txt_adddepartmentadmin.Value });
if (returnResult == "Unsuccessful")
{
ScriptManager.RegisterStartupScript(this, typeof(string), "Error", "alert('That department already exists, please enter a unique name.');", true);
}
else
{
ScriptManager.RegisterStartupScript(this, typeof(string), "Error", "alert('Department added.');", true);
txt_adddepartmentadmin.Value = "";
departmentamended = true;
PopulateDepartments();
}
}
}