如何启用文本框? [英] How to enable a text box?

查看:81
本文介绍了如何启用文本框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好。



我有3个文本框。当我在第一个文本框中输入ID并在数据库中匹配该ID时,剩余的两个文本框将变为启用状态。如果没有,将显示错误消息。怎么做?

解决方案

1。两个文本框的默认状态定义为禁用

2.当第一个文本框中的ID ID与您的id匹配时

 SqlDataReader reader =  null ; 
SqlConnection conn = new SqlConnection( Yourconnectionstring );
conn.Open();
SqlCommand cmd = new SqlCommand( select *来自yourtable,其中your_id = @ URID,conn);
cmd.Parameters.AddWithValue( @ URID,TextBox.Text);
reader = cmd.ExecuteReader();
if (reader!= null && reader.HasRows){
// 启用TextBox2和3
}


使用UpdatePanel。看看以下链接。你会知道该怎么做。





http://msdn.microsoft.com/en-us/library/system.web.ui.updatepanel(v = vs.110) .aspx [ ^ ]



http://stackoverflow.com/questions/1525173/how-do-you-use-an-updatepanel-properly-asp-net [< a href =http://stackoverflow.com/questions/1525173/how-do-you-use-an-updatepanel-properly-asp-nettarget =_ blanktitle =New Window> ^ ]


假设您使用asp:TextBox:

1.在您的标记中添加OnTextChanged =txtID_changed

2. on服务器为你的支票添加protected void txtID_changed(对象发送者,eventargs e)处理程序

3.在处理程序中去t o数据库并验证您的ID

4.如果ID匹配,则txt2.Enabled = true; txt3.Enabled = true; else lblInfo.Text =错误消息 - lblInfo是用于向用户显示消息的控件。



假设你使用jQuery / Ajax

1.在你的输入标签中添加onblur =retutn is_ID_valid();
2.添加你的javascript标签功能is_ID_valid()

3.检查ID(jQuery.ajax调用),如果匹配add


Hi guys.

I have 3 text boxes. When I input an ID on the first text box and matches that ID in the Database, the two remaining text boxes will become enabled. If not, an error message will display. How to do that?

解决方案

1. Default status of the two text boxes define as disables
2. When inter ID in first text box match the values with your id

SqlDataReader reader = null;
SqlConnection conn = new SqlConnection("Yourconnectionstring");
    conn.Open();
    SqlCommand cmd = new SqlCommand("select * from yourtable where your_id=@URID", conn);
cmd.Parameters.AddWithValue("@URID",TextBox.Text);
   reader = cmd.ExecuteReader();
    if(reader!=null && reader.HasRows){
    //Enable TextBox2 and 3
    }


Use UpdatePanel. Have a look at the following links. You will know what to do.


http://msdn.microsoft.com/en-us/library/system.web.ui.updatepanel(v=vs.110).aspx[^]

http://stackoverflow.com/questions/1525173/how-do-you-use-an-updatepanel-properly-asp-net[^]


Assuming you use asp:TextBox:
1. add OnTextChanged="txtID_changed" in your markup
2. on the server add protected void txtID_changed(object sender, eventargs e) handler for your check
3. within the handler go to the database and validate your ID
4. if ID matches, txt2.Enabled = true; txt3.Enabled = true; else lblInfo.Text = "Error message" - lblInfo is the control you use to display messages to the user.

Assuming you use jQuery / Ajax
1. add onblur="retutn is_ID_valid(); in your input tag
2. add in your javascript tag function is_ID_valid()
3. check up the ID (jQuery.ajax call), if it matches add


这篇关于如何启用文本框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆