user123456789 user123456789 - 1 year ago 88
ASP.NET (C#) Question

how to blank a textbox created in the code behind in javascript?

I created a textbox in the code behind:

HtmlGenericControl tdFromCounty = new HtmlGenericControl("td");

TextBox tbFromCounty = new TextBox();
tbFromCounty.CssClass = "rateinput";
tbFromCounty.Style.Add("width", "200px");
tbFromCounty.Text = "";
tbFromCounty.ID = "fc" + this.ID.ToString();
tbFromCounty.Attributes.Add("onblur", "UpdateCellFromCounty(" + this.ID + ",this.value)");

And in javascript I am doing a check to make sure that the value entered into the textbox is a valid county. If it is not valid then I want to blank the textbox.

I have tried these so far but none of them work:

$("#fc"+ result.Element).val == "";
$("#fc"+ result.Element).val = "";
$("#fc"+ result.Element).val("");

Answer Source

Try this:

$("#fc"+ result.Element).attr("value") = "";

Sorry, it should be

$("#fc"+ result.Element).attr("value", "");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download