Click here to Skip to main content
11,630,646 members (79,512 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET WebForms
hi all
i Have A textBox that I Want When I Press a Key ،a Server Function Call!!!

I add OnTextChanged="TextBoxChang" but it Not Works Correctly!!!
when TextBoxChang call that first Focuse and Then Blur and Then Checked For Text is Changing Or not!

i want User Press A Key a Server Function Call!!!
thanks So Much


Failure Is Not An Option
<asp:TextBox ID="TextBoxCaption"  ClientIDMode="Static" runat="server" OnTextChanged="TextBoxCaption_TextChanged">

in server Side:
 protected void TextBoxCaption_TextChanged(object sender, EventArgs e)
    {
//Not Act When i Press Every Key
    }
Posted 1-Apr-13 4:59am
Edited 1-Apr-13 5:17am
v3
Comments
richcb at 1-Apr-13 11:02am
   
Post your code please.
Seyed Ahmad Mirzaee at 1-Apr-13 11:14am
   
i send Thanks
Seyed Ahmad Mirzaee at 1-Apr-13 11:11am
   
<asp:TextBox ID="TextBoxCaption" ClientIDMode="Static" runat="server" OnTextChanged="TextBoxCaption_TextChanged">

in server Side:
protected void TextBoxCaption_TextChanged(object sender, EventArgs e)
{
//Not Act When i Press Every Key
}
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

  Permalink  
Comments
Seyed Ahmad Mirzaee at 1-Apr-13 11:46am
   
Thanks,But I Saw Before and ...
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Try setting the AutoPostBack = true.
  Permalink  
v2
Comments
Seyed Ahmad Mirzaee at 1-Apr-13 11:22am
   
No,It dose Not Work!!!!
Seyed Ahmad Mirzaee at 1-Apr-13 11:23am
   
In Asp Call function Dosent Need '()'
richcb at 1-Apr-13 11:34am
   
You are correct, did you try setting the AutoPostBack = true?
Seyed Ahmad Mirzaee at 1-Apr-13 11:48am
   
Yes.Thanks
richcb at 1-Apr-13 11:50am
   
So it works now?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

You have to use jquery for that, bellow is the example
<script type="text/javascript">
$("#TextBoxCaption").keypress(function () {
     // here is your code

   });

</script>
there is no keypress event in server side

<asp:textbox id="TextBoxCaption" runat="server" ontextchanged="TextBoxCaption_TextChanged" autopostback="true" >

ontextchanged only works when you lost focus from text box and when you give AutoPostBack="true"
  Permalink  
v4
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Here you go:

Your textbox control:
<asp:textbox id="TextBoxCaption" runat="server" xmlns:asp="#unknown">AutoPostBack="true" OnTextChanged="TextBoxCaption_TextChanged"/>
</asp:textbox>

Code behind:
protected void TextBoxCaption_TextChanged(object sender, EventArgs e)
{
    TextBox txt = sender as TextBox;
    if (txt != null)
    {
        //your code here
    }
}

Now, if you want that a function fires by pressing (typing) the A key you need to add the OnKeyPress or KeyDown event, but it need call a javascript function.

Your textbox control:
<asp:textbox id="TextBoxCaption" runat="server" autopostback="true" onkeypress="yourjavascriptfunction():" xmlns:asp="#unknown" />


Javascript function:
function yourjavascriptfunction()
{
    var keyCode = window.event.keyCode;
    if (keyCode == yourkeycode)
    {
      //your code here
    }
}

if this is not what you are looking you can check this info:
http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/844590e7-4625-402f-81b2-333a176041f5/

http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/59e916d8-c2d9-4025-b59b-751a40610b65
  Permalink  

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

  Print Answers RSS


Advertise | Privacy | Mobile
Web01 | 2.8.150723.1 | Last Updated 2 Apr 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100