Click here to Skip to main content
15,917,177 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello.
I have a code,where when user enter values in textbox,on enter-key press,it will move the value to listbox. And when user enter same values (duplicate),it will remove the duplicate value and tell the user on label that duplicate user is detected.
I have this code as in vb as code behind,and its working fine.
But i want it to be on client side events,where no postback when every time the enter key is pressed.

Anyone knows how this code to be applied as client side event code?
VB
Protected Sub txtSerialNo_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtSerialNo.TextChanged
        Dim i As Integer
        Dim ifoundrec As Integer
        i = 0
        ifoundrec = 0
        ifoundrec = LstBoxSerialNo.Items.IndexOfText(txtSerialNo.Text)
        If ifoundrec = -1 Then
            LstBoxSerialNo.Items.Add(txtSerialNo.Text)
            lblStatus.Text = ""
            txtSerialNo.Text = ""
            txtSerialNo.Focus()
            lblSNCount.Text = LstBoxSerialNo.Items.Count

        ElseIf ifoundrec > -1 Then
            lblStatus.Text = txtSerialNo.Text + " is duplicate "
            txtSerialNo.Text = ""
            txtSerialNo.Focus()
        End If
    End Sub
Posted
Updated 15-Dec-10 20:58pm
v2

1 solution

Try some script like this.

HTML
<script>
function checkList()
{
  var list = document.getElementById('listID');
  var txtbox = document.getElementById('txtboxID');
  var lbl = document.getElementById('lblID');
  for(var i = 0; i < list.options.length; i++)
  {
    if(list.options[i].value == txtbox.value)
    {
        lbl.value = "User already exist.";
        return false;
    }
  }
  //add new user here, or get the postback by returning true
}
</script>
 
Share this answer
 
v2
Comments
pwtc222 16-Dec-10 4:09am    
i m using asp.net devexpres textbox.the code above can be used?
Prerak Patel 16-Dec-10 4:40am    
It should work if it is being rendered as input. Just try that. I think you should check the HTML being rendered.
pwtc222 16-Dec-10 19:54pm    
so,can i add this code on key up,in textbox?
Prerak Patel 17-Dec-10 2:29am    
Yes, you can. But check first the pressed key in ENTER and then add this code, or call this function.
pwtc222 22-Dec-10 4:25am    
sorry,but it doesnt seems to works for my devexpress textbox client side key up events.
the code here seems different.
like to set a text in label,its lbl.SetText("User already exist.");
so,i have difficulties in using ur loop code here.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900