时间:2021-07-01 10:21:17 帮助过:8人阅读
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="SearchForm.ascx.cs" Inherits="System_Assets_Report_SearchForm" %>
<div style="margin: 3px;">
资产编号 <asp:TextBox ID="TextBoxAssetsNumber" runat="server" CssClass="textbox" Height="20px" ></asp:TextBox>
<asp:Button ID="ButtonSearch" runat="server" Text="Search" OnClick="ButtonSearch_Click" />
<asp:Button ID="ButtonExport" runat="server" Text="导出至Excel" OnClick="ButtonExport_Click" Enabled="false" />
</div>
为了解决搜索的Click事件在各个页面执行,Insus.NET在用户控件使用委托(delegate):
代码如下:
public delegate void SearchEventHandler(object sender, EventArgs e);
public delegate void ExportEventHandler(object sender, EventArgs e);
另外为了搜索结果是否有记录,对应导出铵钮是否禁用与启用,因此在用户控件写一个带参的方法:
代码如下:
public void EnabledExportButton(bool enabled)
{
this.ButtonExport.Enabled = enabled;
}
还有就是为了把用户控件的文本框的值带结aspx.cs页面,还需要写一个修饰符为public的方法:
代码如下:
public string GetAssetsNumber()
{
return this.TextBoxAssetsNumber.Text.Trim();
}
完整的ascx.cs代码:
代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Insus.NET;
public partial class System_Assets_Report_SearchForm : BaseUserControl
{
public delegate void SearchEventHandler(object sender, EventArgs e);
public delegate void ExportEventHandler(object sender, EventArgs e);
public event SearchEventHandler SearchClick;
public event ExportEventHandler ExportClick;
public string GetAssetsNumber()
{
return this.TextBoxAssetsNumber.Text.Trim();
}
public void EnabledExportButton(bool enabled)
{
this.ButtonExport.Enabled = enabled;
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void ButtonSearch_Click(object sender, EventArgs e)
{
if (SearchClick != null)
SearchClick(this, e);
}
protected void ButtonExport_Click(object sender, EventArgs e)
{
if (ExportClick != null)
ExportClick(this, e);
}
}
各个aspx页,下面只列示一页:
.aspx.cs代码示例: