textbox - KeyPress event on Asp.net [no javascript] - asp.net

I'm designing a website and I want my login page to catch "Enter" with all components, but i can not assign any Key or Mouse Events to TextBox ... After pressing to "Enter" a function should be run with 2 parameters (user name and password).
How can i do this?

If you wrap all the controls inside a standard HTML form then hitting enter in one of the text boxes will submit the form. You can then process the username and password entered on the server as with a normal form submission. Is that the behaviour you're looking for?
You don't need to trap any events on the client in this case so no need for JavaScript.

How to submit ASP.NET forms with the enter key
Read up on the defaultbutton property for forms and panels. This should get you what you want. From the site above:
ASP.NET 2.0 introduces a wonderful work around for this. By simply specifying the "defaultbutton" property to the ID of the , whose event you want to fire, your job is done.
The defaultbutton property can be specified at the Form level in the form tag as well as at panel level in the definition tag. The form level setting is overridden when specified at the panel level, for those controls that are inside the panel.

http://www.beansoftware.com/asp.net-tutorials/accept-enter-key.aspx
finally if found the answer. Here is ! The only problem is, I can not hide my button,
so that i put that button to web page as "Login" ... Defaultbutton could be hidden or not?

Related

ASP.NET TextBox verses input type="text" behavior

I notice with ASP.NET if the server side control TextBox is used with out autopostback it will not submit (or postback) the form when typed text ends with enter, which is different from the behavior for plain old HTML pages. Fine, I can set autopostback to get the behavior I want after the enter key. However, autopostback will also cause submit (or postback) when the typed text does not end with enter but focus has changed (i.e. with tab or mouse click), which again is different from plain old HTML pages.
How can I get an ASP.NET page to behave the same as a plain old HTML page with respect to text input regardless of whether enter key or change of focus occurs?
There is some additional setup work, check out this article: http://geekswithblogs.net/ranganh/archive/2006/04/12/74951.aspx
There is a HtmlInputText class: http://msdn.microsoft.com/en-us/library/f8kdafb5(v=VS.71).aspx
The behavior you are describing isn't asp.net specific. It's whether you are capturing the enter key in JavaScript and submitting the form. I think the key code for the enter key is 13.
After reading your question again. I'm not sure what you mean when you say "plain old Html page." What behavior are you expecting? ASP.Net output is html.

Handle Enter Key on Website (ASP and VB)

So I have a website with multiple asp controls. When I press enter inside by login form, the search function runs because it's the first thing found on the page.
How would I handle the enter button so that when the active textbox is for the login form, the loginbutton code actually runs rather than the searchbutton.
One last problem is that the login controls are inside a loginview so the hierarchy shows that the asp:textbox and asp:button for logging in are inside 3 tags like so:
<loginview>
<login>
<logintemplate>
//controls are here.
</logintemplate>
</login>
Just a note that all controls are asp and that all code is prefered in VB. Thanks
You want to set the default button on the form like this:
Page.Form.DefaultButton = "LoginButtonId"
MSDN Docs: http://msdn.microsoft.com/en-us/library/system.web.ui.htmlcontrols.htmlform.defaultbutton%28VS.80%29.aspx
Also, see this question for an issue I had in Firefox related to this : Default Form Button in FireFox

Setting default button in asp.net 2.0

I have 3rd party user control (a captcha control), which has a captcha image, a text box within it.
I am using the above user control in my webpage. I have a 3 submit buttons on my webpage (Validate Captcha, Submit Page, Add User). When I click the Validate Captcha submit button using the mouse, I am validating whether captcha is empty and showing a javascript alert.
The problem comes when I enter the valid captcha text in the textbox and hit enter key when the cursor is in the textbox. The page just refreshes. I am unable to add keypress event to textbox and call Validate Captcha button event as I am using the 3rd party user control which I cannot modify.
Also, Page.ClientScript.RegisterHiddenField(...) will not work in my case as I have two other submit button inside the same page.
Only option left is to enclose these in panels and set default button.
Please let me know if anyone has any better options for achieving this.
Greetings! I too use alot of third party controls. The thing to remember about these controls, it that in the end they just emit HTML. This means you can use the DOM to access and attach event handlers such as onKeyPress. The trick is to identify how your control creator named the control you are looking for, in this case a {textbox}. The easiest way to achieve this is to simply run the page and view the page source. It is there that you can find the name as it is rendered and sent to the browser, after that all you have to do us use document.getElementByID to get the object and setup your handler
Example:
<script>
//Place this AFTER your textbox control is declared in the HTML
//Get the textbox
var textbox = document.getElementById('nameOfRenderedControlHere');
//Assign the event handler and function you want it to call
textbox.onclick = function() { validateCaptcha(); };
function validateCaptcha()
{ //Do your Stuff here }
</script>
That should be it..havent tested, let me knwo if you run into questions.
Put the captcha in its own <asp:Panel> and add a DefaultButton property for the panel with the ID of the captcha's submit button.

ASP.NET Validation

i have one page to design. in this it includes an , password text box,
My requirment is that when an user hit the submit button without entering any data, then it shows a message in red color at side of both the text box as "Cannot be empty"
How it can be done without using Javascript?
In this instance you would use a RequiredFieldValidator control, drop that in your page. It will by default use javascript and server side. You can turn the javascript off by setting the EnableClientScript property to false. You'd associate this validator with your text box using the ControlToValidate property. Set the Text property to the message you want to display.
On the server side event generated by your button simply call the Page's IsValid property and only if it is valid continue processing.
See Validating Form Input Controls.
I found this tutorial at http://social.msdn.microsoft.com/Search/en-US/?query=asp.net%20validation&ac=8.
You can use validation controls. They support client side and server side validation.
You don't need to know javascript if you mean that.
In ASP.Net you can have Validators.
http://www.dotnetcurry.com/ShowArticle.aspx?ID=121&AspxAutoDetectCookieSupport=1
Short but true =)

ASP.NET validation

I have a little problem with the validation in one form
the form is composed by two taqs. There is a "Save" button in each tap (is the same control for both) and saves the form info. there are validation controls in one tab but not in the second. When we try to save the info from the second tab, and the info has not been filled in the first tab, the validators fire, and nothing happends, but because this validators are shown in the other tab, the end user might be thinking that the operation has been completed, instead, I would like to show a msgBox telling the user about the errors in the other tab. How do I know that the validators in the other tab have been fired, and display the error message when the button is clicked?
You should use the ValidationGroup of your validator controls and the appropriate submit button. You can also use a ValidationSummary control which displays a summary of the validation messages - this can be set to display a message box if you want by setting the property ShowMessageBox=true.
taqs - tap
dear why are you so confused?
All the validators are posted to the page as JavaScript functions. You can call the validation function on button's click and take the appropriate action.
You can use on buttons
onClientClick="Page_ClientValidate();"

Resources