0

I have a

<asp:TextBox ID="tboxUsername" ReadOnly="true" CssClass="fancyInput1" Text="hello" runat="server"></asp:TextBox>

and I would like to set the .Text property with javascript. Unfortunately it does not change and when I call the .Text property in the code behind after the javascipt it still shows the default value ("hello").

this is my javascript

function showModalBox(username, title, firstname, lastname, email, phone, street, ctrycode, zipcode, city, companyname, usertyp, isactive) {

            var modalBox = document.getElementById("modalCompanies");
            var tboxUsername = document.getElementById("<%=tboxUsername.ClientID%>"); // this is my textbox
            var tboxTitle = document.getElementById("tboxTitle");
            var tboxFirstname = document.getElementById("tboxFirstname");
            var tboxLastname = document.getElementById("tboxLastname");
            var tboxEmail = document.getElementById("tboxEmail");
            var tboxPhone = document.getElementById("tboxPhone");
            var tboxStreet = document.getElementById("tboxStreet");
            var tboxCtryCode = document.getElementById("tboxCtryCode");
            var tboxZipCode = document.getElementById("tboxZipCode");
            var tboxCity = document.getElementById("tboxCity");
            var tboxCompanyName = document.getElementById("tboxCompanyName");
            var cboxActive = document.getElementById("cboxActive");

            tboxUsername.value = username; // assign the string username to the textbox
            tboxTitle.value = title;
            tboxFirstname.value = firstname;
            tboxLastname.value = lastname;
            tboxEmail.value = email;
            tboxPhone.value = phone;
            tboxStreet.value = street;
            tboxCtryCode.value = ctrycode;
            tboxZipCode.value = zipcode;
            tboxCity.value = city;
            tboxCompanyName.value = companyname;

            modalBox.style.display = "inline";
        }

And I call this script here

protected void gvTable_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
    {
        gvTable.SelectedIndex = e.NewSelectedIndex;
        string username = (gvTable.SelectedRow.FindControl("lblUsername") as System.Web.UI.WebControls.Label).Text;

        DataTable dt = Connection.Query("SELECT * FROM portalusers WHERE username = '"+username+"'");
        if(dt.Rows.Count > 0)
        {
            string title = dt.Rows[0][dt.Columns.IndexOf("Title")].ToString();
            string firstname = dt.Rows[0][dt.Columns.IndexOf("Firstname")].ToString();
            string lastname = dt.Rows[0][dt.Columns.IndexOf("Lastname")].ToString();
            string email = dt.Rows[0][dt.Columns.IndexOf("Email")].ToString();
            string phone = dt.Rows[0][dt.Columns.IndexOf("Phone")].ToString();
            string street = dt.Rows[0][dt.Columns.IndexOf("Street")].ToString();
            string ctrycode = dt.Rows[0][dt.Columns.IndexOf("CtryCode")].ToString();
            string zipcode = dt.Rows[0][dt.Columns.IndexOf("ZipCode")].ToString();
            string city = dt.Rows[0][dt.Columns.IndexOf("City")].ToString();
            string companyname = dt.Rows[0][dt.Columns.IndexOf("CompanyName")].ToString();
            companyname = companyname.Substring(0, companyname.Length - 1);
            string usertyp = dt.Rows[0][dt.Columns.IndexOf("Usertyp")].ToString();
            string isactive = dt.Rows[0][dt.Columns.IndexOf("Active")].ToString();

            // call the javascript
            ClientScript.RegisterStartupScript(this.GetType(), "showModalBox", $"showModalBox('{username}','{title}','{firstname}','{lastname}','{email}','{phone}','{street}','{ctrycode}','{zipcode}','{city}','{companyname}','{usertyp}','{isactive}')", true);
        }
    }

What am I doing wrong?

4
  • Remove the "disabled" attribute, then change the value, then add the "disabled" attribute back. Does that fix the issue? Commented May 30, 2019 at 13:47
  • @daddygames thank you that was the issue! :) Commented May 30, 2019 at 13:59
  • @daddygames I am new here, I can't mark your comment as correct, can I? Commented May 30, 2019 at 14:01
  • Glad that worked! I made my comment an answer. Happy coding! Commented May 30, 2019 at 14:15

1 Answer 1

1

Remove the "disabled" attribute, then change the value, then add the "disabled" attribute back. Some browsers don't allow changes to a disabled control.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.