如何在回发后将焦点集中在 TextBox 上以及为什么 Repeater 控件在 TextBox 为空时显示数据?
我正在开发一个 C# ASP.NET 4
项目,其中我需要一个搜索框,可以动态搜索数据库表中的内容,并在每次输入时在 Repeater Control
中显示它TextBox
中的字母表。
我已经做到了这一点,但问题是
1)每次输入单个字母时,我都会失去对 TextBox
的关注
2)当我删除 TextBox
中的内容时,Repeater Control
仍然显示数据
<asp:TextBox ID="TextBox1" runat="server" Width="90%"
ontextchanged="TextBox1_TextChanged"
onKeyUp="return serachme()"
AutoPostBack="false"></asp:TextBox>
<script language="javascript" type="text/javascript">
function serachme() {
__doPostBack('<%=TextBox1.UniqueID %>', "onKeyUp");
}
</script>
而且,
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
con.Open();
SqlDataAdapter mycommand2 = new SqlDataAdapter("select qid,title from globalq where title like '%" + TextBox1.Text + "%'", con);
DataSet ds = new DataSet();
mycommand2.Fill(ds);
askQ.DataSource = ds;
askQ.DataBind();
con.Close();
}
我已经看到了 回发后在文本框中设置焦点 和 回发后在 TextBox 中设置焦点 但不理解它,因为我不知道JavaScript
就这么多。
所以我的问题是
1) 如何在每次 __doPostBack
时聚焦于 TextBoX
?
2) 当我删除TextBox
中的内容时,为什么Repeater Control
仍然显示数据以及如何不显示数据?
感谢您提前做出的努力,
尼基尔
I am working on a C# ASP.NET 4
project where I need to have a search box that dynamically searches the content from database's table and shows it in Repeater Control
everytime I enter alphabet in TextBox
.
I have done it upto this but the problem is
1) I am losing focus on TextBox
everytime I enter single alphabet
2) When I erase content in TextBox
, Repeater Control
still shows data
<asp:TextBox ID="TextBox1" runat="server" Width="90%"
ontextchanged="TextBox1_TextChanged"
onKeyUp="return serachme()"
AutoPostBack="false"></asp:TextBox>
<script language="javascript" type="text/javascript">
function serachme() {
__doPostBack('<%=TextBox1.UniqueID %>', "onKeyUp");
}
</script>
And,
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
con.Open();
SqlDataAdapter mycommand2 = new SqlDataAdapter("select qid,title from globalq where title like '%" + TextBox1.Text + "%'", con);
DataSet ds = new DataSet();
mycommand2.Fill(ds);
askQ.DataSource = ds;
askQ.DataBind();
con.Close();
}
I already saw examples of Set focus in TextBox after postback
and Set focus in TextBox after postback but did not understood it coz I dont know JavaScript
that much.
So my Question is
1) How to get focus on TextBoX
everytime I __doPostBack
?
2) When I erase content in TextBox
, Why Repeater Control
still shows data and how to not show that?
Thanks for your efforts in advance,
Nikhil
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你试过这个吗?:
Have you tried this?: