在网页上查找控制

编程入门 行业动态 更新时间:2024-10-24 08:31:40
本文介绍了在网页上查找控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

HTML

<body> <form id="form1" runat="server"> <asp:Button runat="server" ID="a" OnClick="a_Click" Text="apd"/> </form> </body>

code

protected void a_Click(object sender,EventArgs e) { Response.Write(((Button)FindControl("a")).Text); }

这code正常工作。

不过,这code:

HTML

<%@ Page Title="" Language="C#" MasterPageFile="~/Student/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Student_Default" %> <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server"> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <asp:Button runat="server" ID="a" OnClick="a_Click" Text="andj"/> </asp:Content>

code

protected void a_Click(object sender, EventArgs e) { Response.Write(((Button)FindControl("a")).Text); }

这code不工作,的FindControl 收益空 - ?这是为什么

This code does not work and FindControl returns Null - why is this?

的的FindControl 方法工作在一个简单的页面罚款,但在母版页,它不工作?

The FindControl method works in a simple page fine, but in a master page, does it not work?

的ID的 A 更改为 ctl00_ContentPlaceHolder1_a - 如何能找到控制

The ID of the a is changed to ctl00_ContentPlaceHolder1_a - how can find control?

推荐答案

要找到你所搜索 ContentPlaceHolder1 控制首先在内容页面上的按钮。然后使用在 ContentPlaceHolder1 控制的FindControl 功能来搜索您的按钮:

To find the button on your content page you have to search for the ContentPlaceHolder1 control first. Then use the FindControl function on the ContentPlaceHolder1 control to search for your button:

ContentPlaceHolder cph = (ContentPlaceHolder)this.Master.FindControl("ContentPlaceHolder1"); Response.Write(((Button)cph.FindControl("a")).Text);

更多推荐

在网页上查找控制

本文发布于:2023-10-26 12:02:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1530079.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:网页

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!