惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Security Affairs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Jina AI
Jina AI
P
Palo Alto Networks Blog
GbyAI
GbyAI
大猫的无限游戏
大猫的无限游戏
A
Arctic Wolf
Hugging Face - Blog
Hugging Face - Blog
小众软件
小众软件
Y
Y Combinator Blog
T
The Blog of Author Tim Ferriss
Blog — PlanetScale
Blog — PlanetScale
S
Schneier on Security
V
Vulnerabilities – Threatpost
C
Cybersecurity and Infrastructure Security Agency CISA
雷峰网
雷峰网
T
Tenable Blog
人人都是产品经理
人人都是产品经理
T
Tor Project blog
C
Cyber Attacks, Cyber Crime and Cyber Security
AWS News Blog
AWS News Blog
Microsoft Security Blog
Microsoft Security Blog
J
Java Code Geeks
Scott Helme
Scott Helme
SecWiki News
SecWiki News
C
CERT Recently Published Vulnerability Notes
Recorded Future
Recorded Future
I
InfoQ
Security Archives - TechRepublic
Security Archives - TechRepublic
Help Net Security
Help Net Security
Cloudbric
Cloudbric
C
Check Point Blog
Engineering at Meta
Engineering at Meta
TaoSecurity Blog
TaoSecurity Blog
B
Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园_首页
N
News and Events Feed by Topic
云风的 BLOG
云风的 BLOG
MyScale Blog
MyScale Blog
腾讯CDC
量子位
Application and Cybersecurity Blog
Application and Cybersecurity Blog
K
Kaspersky official blog
Vercel News
Vercel News
F
Full Disclosure
T
Troy Hunt's Blog
Forbes - Security
Forbes - Security
S
Security @ Cisco Blogs

博客园 - Steven Xiao

asp.net接收API Post Json数据为空要注意的事项 解决Asp.net 程序在 IIS 5.1 上运行不支持转换Decimal类型小数点的问题 - Steven Xiao 把XML 文件转换为 String 字符串 - Steven Xiao C#语言规范 3.0 版 分享DotNetBar控件制作office 2007风格界面的视频教程(winform office 2007 风格) XMLHttpRequest对象 SQL 2005实现单表分页的查询语句 软件开发者面试百问 分享一个DotNetBar做的三层架构的winForm程序 分享一个不错的js提示信息代码(tooltips) - Steven Xiao - 博客园 dropdownlist实现树型结构的栏目信息 asp.net 2.0实现多语言(二) asp.net 2.0实现多语言(一) 一个封装的在后台弹出JS Alert消息和JS confirm信息以及跳转到指定的页面 一个小小的WEB程序源代码 網絡收藏: 弹出窗口总结 - Steven Xiao gridview 实现全选和反选--补充 收藏的 sql经典语句 ---来自网上 ASP.NET button控件样式
分享实现web用户控件调用.aspx页面里的方法(从而达到访问母页面中控件的目的)
Steven Xiao · 2009-03-07 · via 博客园 - Steven Xiao

今天在一QQ技术群有朋友问: 他在web用户控件中(.ascx)中放了一个dropdownlist控件,一个textbox控件和一个button控件。

现在把此web用户控件添加到一.aspx页面中.要实现单击用户控件中的button控件把搜索出来的结果数据绑定到.aspx页面的gridview控件上去,如何实现呢?

如果gridview控件是放在.ascx文件中的话,那我们直接把搜索出来的数据绑定到它上面就行了。但现在gridview是放在.aspx文件里,也就是说web用户控件要如何才能访问母页面的控件,把数据绑定到母页面的控件上去?

解决方法:

1.先在.aspx页面的后台文件.aspx.cs中添加一个绑定数据的方法,代码如下:

public void BindSearchDataToGridView(string ddlvalue,string txtValue)

{

//ddlvalue 为用户控件中dropdownlist控件的值

//txtValue 为用户控件中textbox控件的值

//通过传进来的参数去查询数据,然后绑定到gridview控件上

//在这里写上绑定数据的方法

}

2.在web用户控件中实现button控件的方法代码如下:

     protected void btnSearch_Click(object sender, EventArgs e)
        {
            System.Web.UI.Page motherPage = this.Page;
            Type pageType = motherPage.GetType();

             //这里用到了反射
            System.Reflection.MethodInfo mi = pageType.GetMethod("BindSearchDataToGridView"); //"BindSearchDataToGridView"为.aspx页面文件的方法
            string txtValue= TextBox1.Text;
            string ddlvalue= DropDownList1.SelectedValue.ToString();
            mi.Invoke(motherPage, new object[] { ddlvalue, txtValue});
        }

 HP laptop battery