自定义控件设计:通过gridview传递参数

一.设计从gridview获取ID和NAMEusing System;using System.Collections.Generic;using System.ComponentModel;using System.Text;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.IO
摘要由CSDN通过智能技术生成

一.设计从gridview获取ID和NAME

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

namespace WebControlLibrary
{
    [DefaultProperty("Text")]
    [ToolboxData("<{0}:GetIDAndName runat=server></{0}:GetIDAndName>")]
    public class GetIDAndName : CompositeControl  //WebControl //, IPostBackEventHandler, IPostBackDataHandler
    {
        [Bindable(true)]
        [Category("Appearance")]
        [DefaultValue("http://blog.csdn.net/zhanghefu/")]
        [Localizable(true)]
        [Description("The address of URL to open by the Button.")]

        public string URL
        {
            get
            {
                String s = (String)ViewState["URL"];
                return ((s == null) ? String.Empty : s);
            }
            set
            {
                ViewState["URL"] = value;
            }
        }

        [Bindable(true)]
        [Category("Appearance")]
        [DefaultValue("0")]
        [Localizable(true)]
        [Description("To set the WindowWidth of URL which is  opened by the Button.")]

        public int WindowWidth
        {
            get
            {
                object o = ViewState["WindowWidth"];
                if (o != null)
                {
                    return int.Parse(ViewState["WindowWidth"].ToString());
                }
                else
                {
                    return 0;
                }
            }
            set
            {
                ViewState["WindowWidth"] = value;
            }
        }

        [Bindable(true)]
        [Category("Appearance")]
        [DefaultValue("0")]
        [Localizable(true)]
        [Description("To set the WindowHeight of URL which is  opened by the Button.")]

        public int WindowHeight
        {
            get
            {
                object o = ViewState["WindowHeight"];
                if (o != null)
                {
                    return int.Parse(ViewState["WindowHeight"].ToString());
                }
                else
                {
                    return 0;
                }
            }
            set
            {
                ViewState["WindowHeight"] = value;
            }
        }

        public TextBox TextBox;
        public TextBox TextBox2;
        //public HiddenField HiddenField;
        public Button Button;

 

        protected override void CreateChildControls()
        {
            TextBox = new TextBox();
            TextBox2 = new TextBox();
            //HiddenField = new HiddenField();
            Button = new Button();

            TextBox.ID = "txtName";
            this.Controls.Add(TextBox);
            TextBox2.ID = "txtID";
            this.Controls.Add(TextBox2);
            //HiddenField.ID = "hfID";
            //HiddenField.Visible = true;
            //this.Controls.Add(HiddenField);
            Button.ID = "btnChoose";
            Button.Text = "选择";
            Button.Click += new EventHandler(Button_Click);

            this.Controls.Add(Button);
        }

      
        public event GetNameAndIDEventHandler OpenDilog;
        protected void Button_Click(object sender, EventArgs e)
        {
            try
            {
                if (URL == "" || URL ==null)
                    {
                        string strRemind = "The URL is not null.please input your URL!";
                         this.Page.RegisterStartupScript(System.Guid.NewGuid().ToString(),"<script>window.alert('" + strRemind + "')</script>");
                    }
                    //else
                    //{
                    //    OpenDilog(this, new SuzsoftArgs(this.Page, URL, WindowWidth, WindowHeight));
                    //}
                if (OpenDilog != null)
                {
                    OpenDilog(this, new SuzsoftArgs(this.Page

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值