我这里有一个由输入框和文本区域组成的代码,但是当我打算输入名为txtBxSearch的输入框时.发生错误,它说"当前上下文中不存在名称'txtBxSearch'"
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<div style="padding-top:10px; padding-left:40px;"> <span class="fields">To:</span><br />
<input type="text" id="txtBxSearch" name="txtBxSearch" class="border fields"
style="width:891px;" onclick="return txtBxSearch_onclick()" />
Run Code Online (Sandbox Code Playgroud)
<div style="padding-top:10px; padding-left:40px;"><span class="fields">Text Message:</span><br />
<textarea id="TextArea1" onkeyup="textCounter(this,'counter',160);" cols="20" rows="2" class="fields border" style="height:150px; width:95%;"></textarea>
Run Code Online (Sandbox Code Playgroud)
</asp:Content>
Run Code Online (Sandbox Code Playgroud)
我的代码落后于C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Data.SqlClient;
using System.Web.Services;
using System.Web.UI.WebControls;
public partial class SMS : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
private string groupKeyword;
private string message;
private int priorityLevel;
private bool isDiagnosticCommand;
private bool concatenate;
private object confirmationDate;
protected void btnSend_Click(object sender, ImageClickEventArgs e)
{
groupKeyword = txtBxSearch.value;
message = TextArea1.Value;
priorityLevel = 253;
//confirmationDate = DateTime.Now.ToShortDateString();
isDiagnosticCommand = false;
concatenate = false;
}
}
Run Code Online (Sandbox Code Playgroud)
因为您的控件txtbxSearch是HTML控件,所以它不是ASP.Net控件.这就是为什么你不能在后面的代码中访问它.
runat="server"使用文本框指定属性,您应该能够在后面的代码中访问它.
您也可以尝试使用代码:
string value = Request.Form["txtbxSearch"];
Run Code Online (Sandbox Code Playgroud)
如果您不想使用runat="server"输入控件.
| 归档时间: |
|
| 查看次数: |
3531 次 |
| 最近记录: |