我在按钮事件里写了很多种获得焦点事件 可是都没有效果 没有一个成功的
希望大家帮帮忙
我的代码
protected void lkbReset_Click(object sender, EventArgs e) //查询重置
{
grvInfo.Columns[0].HeaderText = "修改";
grvInfo.EditIndex = -1;
CompanyName.Text = "";
DeviceNumc.Text = "";
ProductionCompany.Text = "";
DeviceName.SelectedIndex = 0;
SelectListbind(""); //绑定gridview
//btReset.Attributes.Add("onkeydown", "javascript:document.form1.CompanyName.focus();");
//this.RegisterStartupScript("", "<script language='javascript'>{document.form1.CompanyName.focus();}</script>");
//这两种方法都不好用 .Focus()也不好用 js前台代码我也调用了 也不好用
黔驴技穷 请大家帮忙
}
希望大家帮帮忙
我的代码
protected void lkbReset_Click(object sender, EventArgs e) //查询重置
{
grvInfo.Columns[0].HeaderText = "修改";
grvInfo.EditIndex = -1;
CompanyName.Text = "";
DeviceNumc.Text = "";
ProductionCompany.Text = "";
DeviceName.SelectedIndex = 0;
SelectListbind(""); //绑定gridview
//btReset.Attributes.Add("onkeydown", "javascript:document.form1.CompanyName.focus();");
//this.RegisterStartupScript("", "<script language='javascript'>{document.form1.CompanyName.focus();}</script>");
//这两种方法都不好用 .Focus()也不好用 js前台代码我也调用了 也不好用
黔驴技穷 请大家帮忙
}
window.Form1.TxtUser.focus();
PageSize();
}
<body MS_POSITIONING="GridLayout" language="javascript" onload="return window_onload()" scroll="no">
如果没有出问题
那么一般的textbox.Focus()是会起作用的啊。
protected void lkbReset_Click(object sender, EventArgs e) //查询重置
{
grvInfo.Columns[0].HeaderText = "修改";//在这设个断点
grvInfo.EditIndex = -1;
CompanyName.Text = "";
DeviceNumc.Text = "";
ProductionCompany.Text = "";
DeviceName.SelectedIndex = 0;
SelectListbind(""); //绑定gridview
CompanyName.Focus();
}设置个断点看看有没有运行到CompanyName.Focus();
你是不是小菜,我可没说,我只是帮你解决问题。
</form>
但是我测试过 在这里面不影响获得焦点啊
在code project上找到的答案
this.ScriptManager1.SetFocus(txtOldName.ClientID);
这个方法可以解决我的问题