[英]Cant get text from textbox
So, I need to get a string from a textbox to use in a backend program, but I'm unable to get it when im one the site, however it works if i set Text="Test1" prior, even though i change the text in the textbox, "Test1" always gets sent to to my function and works! 因此,我需要从文本框中获取一个字符串以在后端程序中使用,但是当我在一个站点上时我无法获取它,但是即使我更改了Text =“ Test1”,它也可以正常工作文本框中的文本,“ Test1”总是发送到我的函数并起作用! (Talking about Box3)
(谈论Box3)
Code to the text boxes below 编码到下面的文本框中
<div class="row">
<form action="#" method="post" class="contact-form">
<div class="col-md-4 col-sm-6">
<asp:TextBox ID="Box3" Text="Test1" runat="server" placeholder="Gamepin..."></asp:TextBox>
</div>
<div class="col-md-4 col-sm-6">
<asp:TextBox ID="Box2" runat="server" placeholder="Name ..."></asp:TextBox>
</div>
<div class="col-md-4 col-sm-12">
<asp:TextBox ID="Box1" runat="server" placeholder="Amount ..."></asp:TextBox>
</div>
<div >
<asp:CheckBox ID="CheckBoxREPLY" runat="server" style="vertical-align: central" Text="YesNo" TextAlign="Left" />
</div>
<div class="col-md-12 col-sm-12">
<input type="button" runat="server" onserverclick="Funcactivate" class="button big green" value="Launch!"/>
</div>
</form>
</div>
And my code to get textbox.text 和我的代码来获取textbox.text
protected void Funcactivate(object sender, EventArgs e)
{
//Get textbox(s)
string Game = Box1.Text;
string Namepref = Box2.Text;
string Amount = Box3.Text;
}
更改按钮可能有效。
<asp:Button ID="btnLaunch" runat="server" Text="Launch!" class="button big green" OnClick="Funcactivate" CausesValidation="False"/>
If you are using web forms, you should be able to capture the text box entry in the "if(!IsPostBack){...}" event and set it to a variable and use it in your "Funcactivate" method. 如果使用的是Web表单,则应该能够捕获“ if(!IsPostBack){...}”事件中的文本框条目,并将其设置为变量,然后在“ Funcactivate”方法中使用它。
Hello Sleepwalker, here is a code sample that works for me, I am not using the isPostBack. 您好Sleepwalker,这是一个对我有用的代码示例,我没有使用isPostBack。 I am also using an asp:button Instead of using an HTML input control.
我也使用asp:button而不是使用HTML输入控件。
<div>
<asp:TextBox ID="txtBox1" runat="server"></asp:TextBox>
</div>
<div>
<asp:TextBox ID="txtBox2" runat="server"></asp:TextBox>
</div>
<div>
<asp:TextBox ID="txtBox3" runat="server"></asp:TextBox>
</div>
<div>
<asp:Button ID="btnSubmit" runat="server" Text="Button" OnClick="btnSubmit_Click" />
</div>
protected void btnSubmit_Click(object sender, EventArgs e)
{
string game = this.txtBox1.Text.ToString();
string Namepref = this.txtBox2.Text.ToString();
string Amount = this.txtBox3.Text.ToString(); //box3;
}
I fixed it by moving my form to only get the < asp:X, because i discovered that if the < asp:x was nested too deep within a ton of divs, it didnt work properly. 我通过移动表单以仅获取<asp:X来修复它,因为我发现如果<asp:x嵌套在一吨divs内太深,它就无法正常工作。
It may have been due to something else, but it worked for me. 可能是由于其他原因,但是对我有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.