I need to make the Enter key as Tab, changing the focus of the controls.
I tried several methods of javascript and it worked well... but in some ModalPopupExtender when i click in enter, it closes the PopUp, or in other cases that have a gridview with TextBox inside, by clicking enter it also closes a PopUp or generates a postback.
Someone have any solutions?
Thanks for the help!
I fix the problem with this code in Page_load:
GridView.Attributes.Add("onkeydown", "if(event.keyCode==13)return false;");
Thanks!
Related
My application(asp.net) has few dropdowns which are dynamically created and all of them were AutoPostBack="false". if I select Item from dropdown and press enter it makes auto postback in the application. I tried to handle this issue OnKeydown event , but No Use.
Could some one help on the same .
Thanks
Pavan
Pressing submit button triggers the first button(forms default button) on the page.
Set UseSubmitBehavior="False" on your Buttons. This disables the "AutoPostback" on Enter.This prevents Postbacks on Enter completely.
Setting AutoPostBack="false" on a drop down list means it won't post back when you change the selection, the first button in an ASP.NET form is usually the default option so by pressing return you are probably invoking your forms submit button.
To avoid the postback when pressing enter inside a dropdown list it shuld be enough to add
<asp:DropDownList ...... onkeydown="return (event.keyCode!=13)"/>
But you will have se same problem if a user presses the enter key inside every control of the page. to disable the enter key on the entire page this is the code
<body onkeydown = "return (event.keyCode!=13)">
Can you please provide us with your code ? It would be easier to know which control is causing the postback by looking at your code.
My best guess is that you might have an asp.net button having the property "UseSubmitBehavior" set to true so when you are pressing enter the button is what is causing the postback.
To investigate further you can add this line of code to your Page_Load event to detect which control is causing the postback
if(IsPostback){
var controlName = page.Request.Params["__EVENTTARGET"];
}
Please let me know should you need any further clarification. :)
If user don't checked, I want to show asp:ModalPopupExtender and get numeric value from this form.
I'm using asp.net wizard control. I don't know "finish" button id. Can somebody help me?
You should set the target of the ModalPopupExtender as a dummy control, i.e., a hidden Button, LinkButton,... that never is going to be clicked by the user.
The Wizard control have a method called FinishButtonClick. Here is where you have to check the state of the CheckBox and show or not the popup calling to the method Show() of the ModalPopupExtender. You also can call to the Click() method of the hidden control or do it with JavaScript usign the BehaviourID of the ModalPopupExtender. Your choice.
Cheers!
To get "Finish" button id, just open the page in browser & view the rendered html code (Right Click -> View Source). From their you can get the finish button id.
And after getting "Finish" button id, you can easily associate a Client-Side event to do the required job.
I am using asp.net C#.
I have one html input field, and 3 image buttons (asp.net controls)
ImageButton 1 = perform delete operation
ImageButton 2 = perform Edit operation
ImageButoon 3 = perform duplicate operation
My problem occurs when the user presses the enter key when the input field is in focus.
When he presses the enter key the browser automatically fires by default the next button.
In my case it is the delete operation.
How can I prevent this?
Configure DefaultButton property properly.
you can also hide a button at the top of your page/form that will attract the attention of IE when you hit enter.
<button style='position:absolute;left:-1000px'>IE sux</button>
that button won't display on the screen but IE will click it whenever you hit enter. since it has no action on click, nothing will happen.
note: only works in IE9. perhaps useful with the default button option above.
As mentioned above, use the form's defaultbutton property or it you use a panel use that of the panel.
http://msdn.microsoft.com/en-us/library/system.web.ui.htmlcontrols.htmlform.defaultbutton(VS.80).aspx
I've got a gridview/formview, master/detail relationship going on.
When I click a button in my formview (item template), I display an ajaxcontroltoolkit modal popup.
On this popup there is a textbox (several, actually). I want to validate the data in this textbox (at least six digits, so far I'm using a regex validator) before I dismiss the popup.
The validator works, but I can still dismiss the form by clicking OK. What I'd like to do is have the ok button on the popup disabled until the data is good.
I have tried fiddling with some stuff in javascript, but I couldn't make it work, as there seems to be some issues regarding finding controls in a formview.
Any ideas?
Thanks in advance.
Without a postback
You should be able to find a control using the following technique in JavaScript:
$document.getElementById('<%=btnSubmitForm.ClientID%>').disabled = true;
If you're using RegularExpressionValidator, this forum suggests a quick (albeit hacky) way to check and see if your form is valid, without doing a postback:
http://forums.asp.net/t/1114240.aspx
With a postback
You could put the Submit button in its own UpdatePanel, if it isn't already in one, and enable/disable it in the code behind, depending on the value of the validator's IsValid property.
If you're unable to get the enable/disable functionality working, you could simply keep the modal open, so the user can't close it until they enter valid inputs or click Cancel:
protected void BtnSubmitClick(object sender, EventArgs e)
{
if (!regexValidator.IsValid)
{
modalPopupExtender.Show();
}
}
I have an aspx.cs page with the following code:
hypPopup.Attributes.Add("onclick",
"window.open('Popup.aspx',
'',
'height=650,
width=800,
location=no,
toolbar=no,
status=no,
scrollbars=yes,
resizable=yes');
return false"
);
When I click the hypPopup link, the window pops up which is fine, but if I close it and refresh the page, the popup keeps popping up. I have to leave the page and come back for it to stop popping up on every refresh. Is this behavior by default or is there a fix to it?
hypPopup.Attributes.Add is done in the Page_Load
If the hypPopup button is set to run on the server, try removing that. Maybe its causing a repost and something int hat repost triggers the button click, so when you refresh the page its resimulating the repost and the click?
I don't know... just trying to think of something!
I have tested this using both <asp:Hyperlink> and <asp:LinkButton> on both Firefox 3.0.6 and IE 6, neither of which reproduce this sort of behavior. The popup window will not appear if I refresh the page (which is in fact the desired behavior since client-side events should only be fired by specific client-side actions.)
What browser are you using? Is that the exact code being fired, or is there more to it then what is displayed?