這讓我發(fā)瘋。我想做一些簡(jiǎn)單但不知道的事情,因?yàn)槲沂且粋€(gè)絕對(duì)的初學(xué)者。我想獲取文本框中的內(nèi)容,并將它們放入 1 個(gè)標(biāo)簽中,然后使該標(biāo)簽可見。無論我嘗試什么,我都會(huì)不斷收到此錯(cuò)誤,“名稱'submittedData'在此上下文中不存在。我做錯(cuò)了什么?這是后面的代碼:using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Globalization;public partial class _Default : System.Web.UI.Page{protected void Page_Load(object sender, EventArgs e){}protected void submit_Click(object sender, EventArgs e) { submittedData.Text = name.Text + " " + email.Text + " " + phone.Text; submittedData.Visible = true;}}和aspx: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"><link rel="stylesheet" type="text/css" href="StyleSheet.css"></link><title>Coding Club</title></head><body><form id="form1" runat="server"> <div> <h1>Coding club registration form</h1> <label for="name">Your Name:</label> <asp:TextBox ID="name" runat="server" TextMode="SingleLine"></asp:TextBox> </div> <div> <label for="email">Your Email:</label> <asp:TextBox ID="email" runat="server" TextMode="SingleLine"></asp:TextBox> </div> <div> <label for="phone">Your Phone:</label> <asp:TextBox ID="phone" runat="server" TextMode="SingleLine"></asp:TextBox> </div> <div> <asp:Button ID="submit" runat="server" Text="Submit" onclick="submit_Click" /> <asp:Button ID="clear" runat="server" Text="Clear Form" /> </div> <div> <label for="submittedData" runat="server"></label> </div></form></body></html>
2 回答

慕運(yùn)維8079593
TA貢獻(xiàn)1876條經(jīng)驗(yàn) 獲得超5個(gè)贊
您id
在 aspx 文件中的標(biāo)簽元素上缺少屬性
<label id="submittedData" runat="server"></label>

縹緲止盈
TA貢獻(xiàn)2041條經(jīng)驗(yàn) 獲得超4個(gè)贊
您可以更改您的代碼,如下所示:
<asp:Label id="submittedData" runat="server"></asp:Label>
或asp:字面意思。
由于您當(dāng)前的標(biāo)簽不是 asp 服務(wù)器控件,因此您可能無法通過標(biāo)簽來設(shè)置它。
您的基礎(chǔ) html 仍將生成 <label for>
標(biāo)記。
我還注意到您使用過:
<label for="name"> next to your text input box.
您可以使用 <asp:Label id=“l(fā)abelName” AssociatedControlId=“name” runat=“server”>
這樣,如果您單擊標(biāo)簽,您的文本框?qū)@得焦點(diǎn)
- 2 回答
- 0 關(guān)注
- 1136 瀏覽
添加回答
舉報(bào)
0/150
提交
取消