user123456789 user123456789 - 9 months ago 41
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("");


Try this:

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

Sorry, it should be

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