我正在使用客户端函数来清除文本框(服务器控件 runat="server")所以当我使用 jquery 清除它时它显示为空但是当我跟踪代码并检查 textbox.Text 控件时我发现那里的值而不是 null那么如何从客户端的文本框控件的值属性中清除它(我必须从客户端清除它以进行用户交互)
我正在使用以下内容从客户端代码中清除它:
$("#cp1_txtDeathDate").val("");
这是我控制的代码:
<asp:TextBox ID="txtDeathDate" runat="server" ></asp:TextBox>
在后面的代码中:
if (txtDeathDate.Text != "" && DatePattern.IsMatch(txtDeathDate.Text))
{
//do something
}
在萤火虫跟踪:
<input id="cp1_txtDeathDate" type="text" value="26/10/2012" name="ctl00$cp1$txtDeathDate"> // while textbox appeared empty
当用户通过(事件点击)更改复选框的值时,我正在调用 javascript 代码
function checkDead_click() {
if ($("#cp1_chDead").prop("checked") == false) {
$("#cp1_drpDeathReason").attr('disabled', 'disabled');
$("#cp1_txtDeathDate").attr('disabled', 'disabled');
$('#divDeath input#cp1_radDMR_0').attr('checked', true);
$("#divDeath input:radio").attr("disabled", true);
$("#cp1_drpDeathReason").html("");
$("#cp1_txtDeathDate").val("");
}
else {
$("#cp1_drpDeathReason").removeAttr('disabled');
$("#cp1_txtDeathDate").removeAttr('disabled');
$("#divDeath input:radio").removeAttr('disabled');
}
}
$("#cp1_chDead").click(checkDead_click);
protected void Saveform()
{
Demographic Demo = new Demographic();
using (DBEntities DB = new DBEntities())
{
try
{
if (hdFormMode.Value == "edit")
{
string nid = Session["NID"].ToString();
Demo = DB.Demographics.SingleOrDefault<Demographic>(d => d.NID == nid);
}
if (Demo != null || hdFormMode.Value == "new")
{
Demo.NID = litNID.Text;
Demo.BirthDate= txtBirthDate.Text;
Demo.FirstName = txtFirstN.Text;
Demo.FatherName = txtFatherN.Text;
Demo.GrandFName = txtGrandFN.Text;
Demo.FamilyName = txtFamilyN.Text;
if (txtDeathDate.Text != "" && DatePattern.IsMatch(txtDeathDate.Text))
{
Demo.DeathDate = txtDeathDate.Text;
Demo.RealDeathDate = Convert.ToByte("1");
}
else
{
Demo.DeathDate = null;
}
if (chDead.Checked)
Demo.Dead = Convert.ToByte("1");
else
{
Demo.Dead = null;
Demo.DeathReason = null;
Demo.RealDeathDate = null;
Demo.DeathDate = null;
}
if (hdFormMode.Value == "new")
{
CreateDemo(Demo);
}
else
{
if (Demo.EntityState == EntityState.Detached)
{
DB.AttachTo("DBEntities.Dempographics", Demo);
}
DB.ObjectStateManager.ChangeObjectState(Demo, EntityState.Modified);
DB.SaveChanges();
}
}
}
catch (Exception ex)
{
throw;
}
}
}
}