Click here to Skip to main content
15,885,952 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
can i get input textbox value in the code behind without using ajax
Posted
Comments
[no name] 26-Jan-13 2:14am    
What have you tried ??

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:
ASP.NET
<input type="text" id="myInput" runat="server" />
 
Share this answer
 
Comments
jayasree acharyya 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 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 29-Jan-13 12:47pm    
how? please send an example
jayasree acharyya 13-Feb-13 14:54pm    
how to use xmlhttprequest to call text on each keypress on server side
jayasree acharyya 13-Feb-13 14:55pm    
how to use xmlhttprequest
make the input textbox to
C#
runat="server"
 
Share this answer
 
Try this one to access your HTML controls on code behind file
C#
<input type="text" id="txtId" runat="server" />

To fire onkeypress event you can call your javascript function from codebehind file.
you can refer this
 
Share this answer
 
This is the AsP.Net form (eg : Registraion.aspx)

XML
<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):

C#
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.
 
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