简体   繁体   English

通过按钮启用和禁用文本框?(asp.net)

[英]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。

enter image description here在此处输入图片说明

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.

相关问题 如何在ASP.net中启用和禁用jQuery中的文本框 - how to enable and disable a textbox in jQuery in ASP.net ASP.NET CheckBoxes在后面的代码中启用/禁用Textbox - ASP.NET CheckBoxes to Enable/Disable Textbox in code behind 在 asp.net 中运行线程时启用和禁用按钮 - Enable and disable button while running thread in asp.net 验证文本框的正则表达式后,ASP.NET禁用按钮 - ASP.NET Disable Button After Validating Regular Expression of Textbox Asp.net使用jQuery启用/禁用checkboxList - Asp.net enable/disable checkboxList with jQuery 使用下拉asp.net启用/禁用datepicker - enable/disable datepicker with dropdown asp.net 如何使用 JavaScript 在 ASP.Net 中启用基于 GridView 中的文本框的按钮? - How to enable a button based on a TextBox in GridView in ASP.Net using JavaScript? 在回发期间禁用asp.net动态按钮单击事件,然后再启用它 - Disable an asp.net dynamic button click event during postback and enable it afterwards 禁用浏览器后退按钮,但在我的asp.net应用程序中保持启用状态 - disable browsers back button but keep it enable within my asp.net application 如何在构造函数中传递值以启用或禁用asp.net控件中的按钮? - How to pass value in a constructor to enable or disable a button in asp.net control?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM