[英]Enable and disable textbox through button?(asp.net)
enter image description here My tutor gave me the following task: Create a form with 3 buttons(Save(Guardar) Edit(Editar) Delete(Eliminar) ).在此处输入图像描述我的导师给了我以下任务:创建一个带有 3 个按钮的表单(Save(Guardar) Edit(Editar) Delete(Eliminar))。
But my real question is this:但我真正的问题是:
I need to link my text box to my button allowing me to disable it and enable it at will but I can't conect them trough code.我需要将我的文本框链接到我的按钮,允许我禁用它并随意启用它,但我无法通过代码连接它们。
PS:If you answer this question try as much as you can to be specific about the terms you use since I've started learning asp.net a few days ago. PS:如果您回答这个问题,请尽可能详细说明您使用的术语,因为我几天前开始学习 asp.net。
First, you need to create the button event.首先,您需要创建按钮事件。 Double click to the button on your form, then the VB will create a button event automatically.双击窗体上的按钮,VB 会自动创建一个按钮事件。 Now, you can code.现在,您可以编码了。 For ie:对于即:
private void button1_Click(object sender, EventArgs e)
{
textBox1.Enabled = false;//Disable textbox1 on the form
}
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="RedioButton.aspx.cs" Inherits="Shoping_Cart.RedioButton" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Enable Disable Textbox Using Jascript Radio Button Click</title> <script type="text/javascript"> function EnableDisableTextBox() { var status = document.getElementById('<%=rbtEnable.ClientID %>').checked; if (status == true) { document.getElementById('<%=TextBox1.ClientID %>').disabled = false; } else { document.getElementById('<%=TextBox1.ClientID %>').disabled = true; } } </script> </head> <body> <form id="form1" runat="server"> <div> <asp:TextBox ID="TextBox1" runat="server" Width="228px"></asp:TextBox> <br /> <br /> <asp:RadioButton ID="rbtEnable" runat="server" Text="Enable" onclick="javascript:EnableDisableTextBox();" GroupName="1" /> <asp:RadioButton ID="rbtDisable" runat="server" Text="Disable" onclick="javascript:EnableDisableTextBox();" GroupName="1" /> </div> </form> </body> </html>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.