locked
Problem using textbox.enabled = true; RRS feed

  • Question

  • User662762443 posted

    Guys, I have the following problem, I have a gridview, and in it I have buttons to change, edit and delete. However, when I click on the view button, I can disable the textbox field so that the user can only see the data loaded in the textbox fields, however when I click on the view, the textbox properties are still disabled, but I already put enabled = true, even so it doesn't work, it is disabled and it was to be enabled. Could someone suggest me something to solve my problem?

    protected void grvFinancingRegister_RowCommand(object sender, GridViewCommandEventArgs e)
            {
                this.codeCompany = int.Parse(e.CommandArgument.ToString());
                try
                {
                    string command = e.CommandName;
                    switch (command)
                    {
                        case "Change":
                            this._code = int.Parse(e.CommandArgument.ToString());
                            financingContext = aplFinancing.SearchByIDFinancing(this._code);
    
                            TextBoxYearBaseMonth.Attributes["Enabled"] = "Enabled";
                            txtYearMonthBilling.Attributes["Enabled"] = "Enabled";
                            txtICMS.Attributes["Enabled"] = "Enabled";
                            txtVlrFinancing.Attributes["Enabled"] = "Enabled";
                            TextBoxTotalCollection.Attributes["Enabled"] = "Enabled";
                           
                            LoadTxtBox();
                            
                            btnNew.Visible = false;
                            btnSave.Visible = true;
    
                            break;
    
                        case "Delete":
                            this._code = int.Parse(e.CommandArgument.ToString());
                            financingContext = aplFinancing.SearchByIDFinancing(this._code);
                            try
                            {
                                aplFinancing.delete(financingContext);
                            }
                            catch (Exception ex)
                            {
    
                                Error = "error";
                                msgError = "Error changing a financing";
                                
                                throw ex;
                            }
                            try
                            {
                                UploadGridFinancing();
                                ClearFields();
                                if (keyJS) chamarSwal("sucess", "Financing excluded!");
                            }
                            catch (Exception ex)
                            {
                                tipoError = "Warning";
                                msgError = "Successfully deleted, but it was not possible to register in the audit.";
                                throw ex;
                            }
                            break;
    
                        case "visualize":
                            this._code = int.Parse(e.CommandArgument.ToString());
                            financingContext = aplFinancing.SearchByIDFinancing(this._code);
    
                            TextBoxYearBaseMonth.Attributes["disabled"] = "disabled";
                            txtYearMonthBilling.Attributes["disabled"] = "disabled";
                            txtICMS.Attributes["Enabled"] = "disabled";
                            txtVlrFinancing.Attributes["disabled"] = "disabled";
                            TextBoxTotalCollection.Attributes["disabled"] = "disabled";
                            btnNew.Visible = false;
                            
                            break;
                    }
                }
                catch (Exception ex)
                {
                    ex.Message.ToString();
                    chamarSwal(tipoError, msgError);
                   
                }
    
            }
    private void LoadTxtBox()
            {
                TextBoxYearBaseMonth.Text = financingContext.YearBaseMonth;
                txtYearMonthBilling.Text = financingContext.YearMonthBilling;
                txtICMS.Text = financingContext.VlrICMSProvided.ToString("N2");
                txtVlrFinancing.Text = financingContext.VlrFinancing.ToString("N2");
                TextBoxTotalCollection.Text = financingContext.TotalCollection.ToString("N2");
                
            }

    my aspx grid:

     <div class="col-md-12" id="divCadFinanciamento">
                <div class="content-box content-box-tabela" id="tabela" style="visibility: hidden">
                    <asp:GridView class="tabela-padrao tabela-padrao-borda dataTable" ClientIDMode="Static" runat="server" ID="grvCadFinanciamento" OnPageIndexChanging="grvCadFinanciamento_PageIndexChanging1" OnRowCommand="grvCadFinanciamento_RowCommand" AutoGenerateColumns="False" PageSize="9">
                        <Columns>
                            
                            <asp:TemplateField HeaderText="Ações" ItemStyle-Width="8%" ItemStyle-HorizontalAlign="Center" HeaderStyle-CssClass="center">
                                <ItemTemplate>
                                    <asp:LinkButton ID="btnChange" runat="server" OnClientClick="return true;" Enabled="true" CausesValidation="false" CssClass="fa fa-edit" Font-Size="Larger"
                                        CommandName="Change" CommandArgument='<%#DataBinder.Eval(Container.DataItem,"Code")%>' ToolTip="Change" BorderStyle="None" Width="30%" />
                                    <asp:LinkButton ID="btnDelete" OnClientClick="if(!confirm('Do you really want to delete that item?')) return false;" runat="server" CausesValidation="false" CssClass="fa fa-trash" Font-Size="Larger"
                                        CommandName="Delete" CommandArgument='<%#DataBinder.Eval(Container.DataItem,"Code")%>' ToolTip="Delete" BorderStyle="None" Width="30%" />
                                    <asp:LinkButton ID="btnVisualize" runat="server" OnClientClick="return true;" CausesValidation="false" CssClass="fa fa-eye" Font-Size="Larger"
                                        CommandName="Visualize" CommandArgument='<%#DataBinder.Eval(Container.DataItem,"Code")%>' ToolTip="Visualize" BorderStyle="None" Width="30%" />
                                </ItemTemplate>
                                <ItemStyle />
                            </asp:TemplateField>
                        </Columns>
                        <PagerStyle CssClass="" HorizontalAlign="Center" />
                    </asp:GridView>

    Wednesday, May 13, 2020 8:15 PM

Answers

  • User662762443 posted

    Friends, I managed to solve my problem using:

    txtboxExemple.Attributes.Remove("disabled");

    Thank you my friend PatriceSc

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 13, 2020 9:04 PM

All replies

  • User753101303 posted

    Hi,

    What if just using myTextBox.Enabled=true as shown in the title of your question? For now you try to define the "enabled" attribute which doesn"r exist for input text fields. Also I woud use attributes only for features not exposed by the control.

    Wednesday, May 13, 2020 8:36 PM
  • User662762443 posted

    PatriceSc, suppose I went there in the gridview and clicked on the view button, and then in the textbox fields the data that was in my grid is displayed, but the user cannot change it, but if he decides to change the data and click on change button, when loading the data in the textbox, the data is loaded to edit, but it is disabled, and so I can't change it for that reason, I would like to correct this problem. I've already passed type like this: txtExample.enabled = true, but it doesn't work.

    Wednesday, May 13, 2020 8:48 PM
  • User662762443 posted

    Friends, I managed to solve my problem using:

    txtboxExemple.Attributes.Remove("disabled");

    Thank you my friend PatriceSc

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 13, 2020 9:04 PM
  • User753101303 posted

    Not sure why you are going back to HTML attributes when using this kind of higher level control ie :

     <asp:TextBox runat="server" ID="a" Enabled="true" />
     <asp:TextBox runat="server" ID="b" Enabled="false" />

    is rendered as (and of course you can set the Enabled property from code) :

     <input name="ctl00$MainContent$a" type="text" id="MainContent_a" />
     <input name="ctl00$MainContent$b" type="text" id="MainContent_b" disabled="disabled" class="aspNetDisabled" />

    Edit Enabled=true might not work because previously you used myTextBox.Attributes["disabled"]="disabled"; rather than myTextBox.Enabled=false;

    Wednesday, May 13, 2020 9:15 PM