1、在一个文件夹里,右击选择添加用户控件
起一个名字
好了后
最开始的样子
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControlTest.ascx.cs" Inherits="webctrltest_WebUserControlTest" %>
Literal 控件用于在页面上显示文本。此文本是可编程的。
注释:该控件不允许您向其内容应用样式!
TextBox 控件用于创建用户可输入文本的文本框。
HiddenField控件是隐藏输入框的服务器控件,他能让你保存那些不必显示在页面上的且对安全性需求不高的数据
前面的
<link href="../qdcss/Style02.css" rel="stylesheet" /> <table class="ttable_border_none" border="0" cellpadding="0" cellspacing="0"><tr><td> <asp:Literal ID="LiteralTitle" runat="server"></asp:Literal><asp:TextBox ID="tbJieSuanTitle" runat="server" ReadOnly="true"></asp:TextBox> <asp:HiddenField ID="HidJieSuanGuid" runat="server" /> <asp:HiddenField ID="HidJieSuanMonth" runat="server" /> <asp:HiddenField ID="HidJieSuanTitle" runat="server" /> </td> <%if (_Select == "sel") %> <%{ %> <td> <a href="javascript:return false;" onclick="javascript:WebDialogLoad(‘选择‘,800,600, ‘JieSuanTitle_order_win.aspx?pwidth=780&pheight=480&c1=<%=HidJieSuanGuid.ClientID %>&c2=<%=HidJieSuanMonth.ClientID %>&c3=<%=HidJieSuanTitle.ClientID %>&c4=<%=tbJieSuanTitle.ClientID %>&edit=<%=_Edit %>&flag=<%=_iFlag %>‘)"> <img src="../../qdadmin/qdimages/sel.png" border="0" title="选择"></a> </td><td> <asp:LinkButton ID="btnClear" runat="server" OnClick="btnClear_Click"><img src="../../qdadmin/qdimages/cuo.png" border="0" title="清除"></asp:LinkButton> </td><td> <%} %> </tr></table>
后面的
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class qdAdmin_MeiDie_WebCtrl_JieSuanTitle : System.Web.UI.UserControl { private ITEM.Inherits.Bll.qdMis4.bllmdJieSuanTitle _bllTitle = new ITEM.Inherits.Bll.qdMis4.bllmdJieSuanTitle(); public PageBase pbase = new PageBase(); protected void Page_Load(object sender, EventArgs e) { this.tbJieSuanTitle.Text = _HidJieSuanTitle; } public string _HidJieSuanGuid { get { return this.HidJieSuanGuid.Value; } set { this.HidJieSuanGuid.Value = value; } } public string _HidJieSuanMonth { get { return this.HidJieSuanMonth.Value; } set { this.HidJieSuanMonth.Value = value; } } public string _HidJieSuanTitle { get { return this.HidJieSuanTitle.Value; } set { this.HidJieSuanTitle.Value = value; } } public string _Width { get { return ViewState["_Width"].ToString(); } set { ViewState["_Width"] = value; } } public string _LiteralTitle { get { return this.LiteralTitle.Text; } set { this.LiteralTitle.Text = value; } } public string _Edit { get { if (ViewState["_Edit"] == null) return "show"; else return ViewState["_Edit"].ToString(); } set { ViewState["_Edit"] = value; } } public string _Select { get { if (ViewState["_Select"] == null) return "nosel"; else return ViewState["_Select"].ToString(); } set { ViewState["_Select"] = value; } } public int _iFlag { get { if (ViewState["_iFlag"] == null) return 0; else return Convert.ToInt32(ViewState["_iFlag"]); } set { ViewState["_iFlag"] = value; } } protected void btnClear_Click(object sender, EventArgs e) { _HidJieSuanGuid = string.Empty; _HidJieSuanMonth = string.Empty; _HidJieSuanTitle = string.Empty; _LiteralTitle = string.Empty; this.tbJieSuanTitle.Text = string.Empty; } public void SetTitle(string sHidJieSuanGuid, string sHidJieSuanMonth, string sHidJieSuanTitle, string sWidth, string sLiteralTitle) { _HidJieSuanGuid = sHidJieSuanGuid; _HidJieSuanMonth = sHidJieSuanMonth; _HidJieSuanTitle = sHidJieSuanTitle; tbJieSuanTitle.Attributes.Add("style", "width:" + sWidth); _LiteralTitle = sLiteralTitle; } public void SetTitle(string sHidJieSuanGuid, string sHidJieSuanMonth, string sHidJieSuanTitle, string sWidth) { SetTitle(sHidJieSuanGuid, sHidJieSuanMonth, sHidJieSuanTitle, sWidth, string.Empty); } public void SetTitle(string sHidJieSuanGuid, string sHidJieSuanMonth, string sHidJieSuanTitle) { SetTitle(sHidJieSuanGuid, sHidJieSuanMonth, sHidJieSuanTitle, "121px", string.Empty); } public void SetTitle(string sWidth) { SetTitle(string.Empty, string.Empty, string.Empty, sWidth, string.Empty); } /////1111111111111 //public void SetTitle(string sHidJieSuanGuid, string sHidJieSuanMonth, string sHidJieSuanTitle, string sWidth, int iFlag) //{ // SetTitle(sHidJieSuanGuid, sHidJieSuanMonth, sHidJieSuanTitle, sWidth, string.Empty, iFlag); //} //public void SetTitle(string sHidJieSuanGuid, string sHidJieSuanMonth, string sHidJieSuanTitle, int iFlag) //{ // SetTitle(sHidJieSuanGuid, sHidJieSuanMonth, sHidJieSuanTitle, "121px", string.Empty, iFlag); //} //public void SetTitle(string sWidth, int iFlag) //{ // SetTitle(string.Empty, string.Empty, string.Empty, sWidth, string.Empty, iFlag); //} public void SetValue(string sTitleGuid) { if (sTitleGuid != string.Empty) { ITEM.Model.qdMis4.mdJieSuanTitle mTitle = _bllTitle.GetModelSelmdJieSuanTitle3("*", pbase.EnterpriseGuid, _iFlag, sTitleGuid); if (mTitle == null) { string s = Request["menu"] == null ? "" : Request["menu"].ToString(); Response.Redirect("PageError.aspx?menu=" + s); } if (mTitle != null) { this.HidJieSuanGuid.Value = mTitle.JieSuanTitleGuid; this.HidJieSuanMonth.Value = mTitle.YearMouth; this.HidJieSuanTitle.Value = mTitle.YearMouthTitle; this.tbJieSuanTitle.Text = mTitle.YearMouthTitle; } } } //public void SetValue(string sTitleGuid) //{ // SetValue(sTitleGuid, 0); //} }
将其放到前端里
后面控制传值
用于查询
前端的展示