如何从主页面获取输入控件的值?
我的母版页:
.......
<div class="searchform">
<form id="formsearch" name="formsearch" method="post" action="#">
<span>
<input name="editbox_search" class="editbox_search" id="editbox_search" maxlength="80" value="Code Client:" type="text" />
</span>
<input name="button_search" src="images/search_btn.gif" class="button_search" type="image" />
</form>
</div>
</div>
<div class="clr"></div>
</div>
</div>
<div class="content">
<div class="content_resize">
<div class="mainbar">
<div class="article">
<form id="form1" runat="server">
<div>
<asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
</div>
.....
和我使用MasterPAge的default.aspx:
protected void Page_Load(object sender, EventArgs e)
{
Label ClientId = (Label)Master.FindControl("editbox_search");
ASPxLabel_Err.Text = ClientId.Text;
}
我尝试将输入Control转换为Label,因为我找不到输入控件。
但我得到了nullReference这个逻辑,因为我无法将输入控件转换为标签控件。
答案 0 :(得分:1)
var editbox = (HtmlInputControl)Master.FindControl("editbox_search");
Response.Write (editbox.Value);
答案 1 :(得分:0)
试试这个
var mastertxt = (System.Web.UI.HtmlControls.HtmlInputText)Master.FindControl("ctl00$editbox_search");
ASPxLabel_Err.Text = mastertxt.Value;
答案 2 :(得分:0)
首先,您需要将此标记设为“runat = server”,然后才能使用:
var txtEditBox =(System.Web.UI.HtmlControls.HtmlInputText)this.Page.Master.FindControl(“editbox_search”);
ASPxLabel_Err.Text = txtEditBox.Value;