Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
can i get input textbox value in the code behind without using ajax
Posted 25-Jan-13 18:26pm
Comments
Krunal Rohit at 26-Jan-13 2:14am
   
What have you tried ??
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

can i get input textbox value in the code behind without using ajax
If you add attribute "runat" & "id" to your input then you can access it in your code behind without using Ajax.
Ex:
<input type="text" id="myInput" runat="server" />
  Permalink  
Comments
jayasree acharyya at 27-Jan-13 15:19pm
   
actually i want to use keypress event in the code behind for the textbox. Server COntrols dont have keypress event. i want to get the text for each keypress in the textbox.
Sandeep Mewara at 28-Jan-13 0:04am
   
HTML input element has onkeypress event - it will be raised on client side. If you need text on each keypress on server side, you need to use xmlhttprequest in onkeypress method.
jayasree acharyya at 29-Jan-13 12:47pm
   
how? please send an example
jayasree acharyya at 13-Feb-13 14:54pm
   
how to use xmlhttprequest to call text on each keypress on server side
jayasree acharyya at 13-Feb-13 14:55pm
   
how to use xmlhttprequest
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

make the input textbox to
runat="server"
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Try this one to access your HTML controls on code behind file
<input type="text" id="txtId" runat="server" />
To fire onkeypress event you can call your javascript function from codebehind file.
you can refer this
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

This is the AsP.Net form (eg : Registraion.aspx)
 
<form id="form1" runat="server">
    <fieldset class="register">
             <asp:Label ID="AccountNameLabel" runat="server"                AssociatedControlID="AccountNameText">Name:</asp:Label>
             <asp:TextBox ID="AccountNameText" runat="server"></asp:TextBox>
 
        <asp:Button ID="CreateUserButton" runat="server" CommandName="MoveNext"
                                Text="Proceed with Registration" CssClass="button fright"
                                onclick="CreateUserButton_Click" />
    </fieldset>
</form>
 
The above code enables the TextBox control to be accessed from the Code behind file.
you can simply achieve this by(from - Registraion.aspx.cs):
 
string strName = AccountNameText.Text;
 
Could you Please refer the following links?
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.textbox.aspx[^]
http://www.w3schools.com/aspnet/aspnet_textbox.asp[^]
 
YOU ALWAYS CAN LEARN SOMETHING ONLY BY DOING RESEARCH BY YOURSELF RATHER ASKING THE SOLUTION FROM OTHERS. The question you asked here is very basic. If you have any questions first you go to goolge and search. Good luck.
  Permalink  

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



Advertise | Privacy | Mobile
Web03 | 2.8.141022.1 | Last Updated 28 Jan 2013
Copyright © CodeProject, 1999-2014
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