Reputation: 13
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?
Upvotes: 0
Views: 45
Reputation: 1928
Remove the "disabled" attribute, then change the value, then add the "disabled" attribute back. Some browsers don't allow changes to a disabled control.
Upvotes: 1