Click here to Skip to main content
15,884,629 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Updated 1-Apr-13 5:17am
v3
Comments
Richard C Bishop 1-Apr-13 11:02am    
Post your code please.
Seyed Ahmad Mirzaee 1-Apr-13 11:14am    
i send Thanks
Seyed Ahmad Mirzaee 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
}

 
Share this answer
 
Comments
Seyed Ahmad Mirzaee 1-Apr-13 11:46am    
Thanks,But I Saw Before and ...
Try setting the AutoPostBack = true.
 
Share this answer
 
v2
Comments
Seyed Ahmad Mirzaee 1-Apr-13 11:22am    
No,It dose Not Work!!!!
Seyed Ahmad Mirzaee 1-Apr-13 11:23am    
In Asp Call function Dosent Need '()'
Richard C Bishop 1-Apr-13 11:34am    
You are correct, did you try setting the AutoPostBack = true?
Seyed Ahmad Mirzaee 1-Apr-13 11:48am    
Yes.Thanks
Richard C Bishop 1-Apr-13 11:50am    
So it works now?
You have to use jquery for that, bellow is the example
<script type="text/javascript">
C#
$("#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"
 
Share this answer
 
v4
Here you go:

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


Code behind:
C#
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.NET
<asp:textbox id="TextBoxCaption" runat="server" autopostback="true" onkeypress="yourjavascriptfunction():" xmlns:asp="#unknown" />



Javascript function:
JavaScript
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
 
Share this answer
 

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