这是我的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#,因为我将来会使用.dll。
答案 0 :(得分:1)
通过包含属性Runat="server"
将这些控件作为服务器端控件,然后您可以在后面的代码中的任何位置访问这些控件实例值(我的意思是*.cs
文件)。