日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

获得用户控件的值!

發布時間:2025/5/22 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 获得用户控件的值! 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
給你一個例子吧,一共四個文件,你拷貝到VS中編譯一下:

my.ascx:

<%@ Control Language="c#" AutoEventWireup="false" Codebehind="my.ascx.cs" Inherits="test.my" TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>

<asp:TextBox id="TextBox1" runat="server">a4w</asp:TextBox>



my.ascx.cs:

namespace test

{

using System;

using System.Data;

using System.Drawing;

using System.Web;

using System.Web.UI.WebControls;

using System.Web.UI.HtmlControls;



/// <summary>

///my 的摘要說明。

/// </summary>

public class my : System.Web.UI.UserControl

{

protected System.Web.UI.WebControls.TextBox TextBox1;



public string Retu1{

get{

return this.TextBox1.Text;

}

set{

this.TextBox1.Text = value;

}

}

private void Page_Load(object sender, System.EventArgs e)

{

// 在此處放置用戶代碼以初始化頁面
}

#region Web 窗體設計器生成的代碼

override protected void OnInit(EventArgs e)

{

//

// CODEGEN: 該調用是 ASP.NET Web 窗體設計器所必需的。

//

InitializeComponent();

base.OnInit(e);

}



/// <summary>

///設計器支持所需的方法 - 不要使用代碼編輯器

///修改此方法的內容。

/// </summary>

private void InitializeComponent()

{

this.Load += new System.EventHandler(this.Page_Load);



}

#endregion

}

}



webform1.aspx:

<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="test.WebForm1" %>

<%@ Register TagName="abc" TagPrefix="my" src="my.ascx" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >

<HTML>

<HEAD>

<title>WebForm1</title>

<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">

<meta name="CODE_LANGUAGE" Content="C#">

<meta name="vs_defaultClientScript" content="JavaScript">

<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">

</HEAD>

<body>

<form id="Form1" method="post" runat="server">

<my:abc id="myAscx" runat="server" /><FONT face="宋體"><BR>

</FONT>

<asp:Button id="Button1" runat="server" Text="Button"></asp:Button>

</form>

</body>

</HTML>



webform1.aspx.cs:

using System;

using System.Collections;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Web;

using System.Web.SessionState;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.HtmlControls;

using ICSharpCode.SharpZipLib.BZip2;



namespace test

{

/// <summary>

/// WebForm1 的摘要說明。

/// </summary>

public class WebForm1 : System.Web.UI.Page

{

protected System.Web.UI.WebControls.Button Button1;

protected test.my myAscx;

private void Page_Load(object sender, System.EventArgs e)

{

// 下面讀取控件的值

Response.Write(myAscx.Retu1);

}



#region Web 窗體設計器生成的代碼

override protected void OnInit(EventArgs e)

{

//

// CODEGEN: 該調用是 ASP.NET Web 窗體設計器所必需的。

//

InitializeComponent();

base.OnInit(e);

}


/// <summary>

/// 設計器支持所需的方法 - 不要使用代碼編輯器修改

/// 此方法的內容。

/// </summary>

private void InitializeComponent()

{???

this.Button1.Click += new System.EventHandler(this.Button1_Click);

this.Load += new System.EventHandler(this.Page_Load);

}

#endregion

private void Button1_Click(object sender, System.EventArgs e)

{

//下面設置控件的值

myAscx.Retu1 = "ddd";

}

}

}

轉載于:https://www.cnblogs.com/star250/archive/2007/03/30/694344.html

總結

以上是生活随笔為你收集整理的获得用户控件的值!的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。