asp Textbox.text属性不会随javascript

时间:2019-05-30 13:42:08

标签: javascript asp.net

我有一个

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

,我想使用javascript设置.Text属性。不幸的是,它并没有改变,当我在javascipt之后的代码中调用.Text属性时,它仍然显示默认值(“ hello”)。

这是我的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";
        }

我在这里叫这个脚本

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);
        }
    }

我在做什么错了?

1 个答案:

答案 0 :(得分:1)

删除“ disabled”属性,然后更改值,然后再添加“ disabled”属性。某些浏览器不允许更改禁用的控件。