如何“;发送“;将数据形成为C#代码;发送“;数据返回
本文关键字:发送 数据 代码 返回 如何 | 更新日期: 2023-09-27 17:59:58
这是我的HTML表单,我想将用户的选择发送到一个aspx.cs文件,该文件将处理他们的选择并在下面的文本框中输出一些内容。
<!-- Form -->
<form action="lGen.aspx" method="post" id="lForm" runat="server">
<div class="row">
<div class="input-field col s6">
<select id="list" form="lForm">
<option value="" disabled="disabled" selected="selected">Select</option>
<option value="1" class="validate" >Option 1</option>
</select>
</div>
<div class="input-field col s6">
<input placeholder="Instert Text" id="insText" type="text" class="validate" runat="server" />
<label for="system_id"></label>
</div>
</div>
<div class="row">
<div class="input-field col s6">
Checkbox
<p class="black-text">
<input type="checkbox" class="filled-in" id="check1" />
<label for="check1"><span class="black-text">Check 1</span></label>
</p>
<p class="black-text">
<input type="checkbox" class="filled-in" id="check2" />
<label for="check2"><span class="black-text">Check 2</span></label>
</p>
</div>
<div class="input-field col s6">
Radio
<p>
<input class="with-gap" name="licenseType" type="radio" id="radio1" />
<label for="radio1"><span class="black-text">Permanent</span></label>
</p>
</div>
</div>
<div class="row">
<br />
<button class="btn waves-effect waves-light black" onclick="generate_onclick()">
Generate
</button>
</div>
</form>
<!-- TEXT AREA-->
<div class="row">
<div class="input-field col s12">
<textarea id="genText" class="materialize-textarea"></textarea>
<label for="genText"><span class="black-text">Generated</span></label>
</div>
</div>
我的aspx.cs是这样的:
namespace lGenerator
{
public partial class WebForm1 : System.Web.UI.Page
{
public string list{ get; set; }
public bool check1{ get; set; }
public bool check2{ get; set; }
public bool radio1{ get; set; }
public string genText { get; set; }
// Generate License on Click button
private void generate_onclick(object sender, EventArgs e)
{
genL();
}
// Creating actual license
private void genL()
{
string phrase = list;
licenseText = phrase;
}
}
}
只是为了测试,我想传递他们在列表中选择的值,然后在下面的文本框中显示。我知道在PHP中,你可以使用$_POST之类的东西从POST中获取值,但我如何使用HTML和C#呢?
注意,我必须更改一些值/ID,我需要让它与C#一起使用,因为我将来将使用.dlls。
通过包含属性Runat="server"
使这些控件成为服务器端控件,然后您可以在代码后面的任何位置访问这些控件实例值(我指的是*.cs
文件)。