使用反射把用户控件(ASCX)传至网页(ASPX)
生活随笔
收集整理的這篇文章主要介紹了
使用反射把用户控件(ASCX)传至网页(ASPX)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
用戶控件向網頁傳遞值,方法非常之多,此博文嘗試使用反射來實現。在站點中,建一個網頁以及一個用戶控件。 網頁切換至設計模式,拉用戶控件至網頁上。
Default.aspx:
View Code <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><%@ Register Src="InsusUC.ascx" TagName="InsusUC" TagPrefix="uc1" %><!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"><title></title> </head> <body><form id="form1" runat="server"><div><uc1:InsusUC ID="InsusUC1" runat="server" /><br /><br />Hi, You input infor as below:<br />first textbox value:<asp:Label ID="LabelshowFirstValue" runat="server" Text="" ForeColor="Red"></asp:Label><br />Second textbox value:<asp:Label ID="LabelshowLastValue" runat="server" Text="" ForeColor="Red" ></asp:Label></div></form> </body> </html>
Default.aspx.cs,建一個帶兩個參數的public方法。
接下來,我們創建一個用戶控件:
寫銨鈕事件,首先引用namespace ?using System.Reflection;
有關type.InvokeMember()方法,可以參考msdn:http://msdn.microsoft.com/zh-cn/library/de3dhzwy(v=vs.80).aspx
演示:
?
超強干貨來襲 云風專訪:近40年碼齡,通宵達旦的技術人生總結
以上是生活随笔為你收集整理的使用反射把用户控件(ASCX)传至网页(ASPX)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SIEM的隐忧
- 下一篇: seach和seachd的区别