how to make asp:LinkButton work in safari when enter pressed - asp.net

I have asp:LinkButton (submit button) and it works properly in every browser. However, in safari it works only if user clicks the submit button and doesn't work if enter is pressed. How can I solve this? I just want this to work similarly in every browsers.
Thanks in advance :)

A LinkButton control turns into an <a> tag in html with a javascript onclick event which will trigger a postback to your webform. What I would do is view the source of the page and find this onclick javascript code, then follow the instructions in this stackoverflow post to add an enter key handler to your linkbutton:
JS enter key press handler
In the event handler for the enter key, put in the onclick code you found from the html source.

Related

.Net textbox is null when a "submit" link is clicked

Good day,
I have a problem in a .NET page where I am using an asp:textbox in combination with an OnClick action on a link button.
What happens is that after text has been entered into the textbox, if you directly click on the link button, more often than not the textbox is considered to be null.
If you click off the text box first then click the link, all is well and the save function performed by the link button proceeds as expected.
My assumption is that there is a lifecycle event that is being missed, or not applied which is not binding the text to the textbox for use in the codebehind when the link button is clicked.
The question is, what can i do to enforce that binding short of doing something like adding an onkeypress event to the textbox to force a postback.
There must be a more elegant solution.
Thank you in advance for your help.
Do you have initializations on your textbox inside Page_Load event? If so, use IsPostBack=false and put the initialization inside.
If IsPostBack =False Then
TextBox1.text=""
End If

ASP.NET Textbox TextChanged and Button OnClick event interaction?

I've got an ASP.NET application that I'm accessing through Google Chrome. On a particular page I've got an asp:TextBox with a OnTextChanged event that recalculates a few other fields on the page. I've also got an asp:LinkButton with an OnClick event that saves the changes to the database.
I was facing a problem where the user left the TextBox by clicking on the save button. The button was firing before the TextChanged event so the changes were not being captured in the save. I fixed this by duplicating the TextChanged logic at the beginning of the save method. Did some testing before I committed these changes and everything was working fine.
But now my tester is facing a different problem. When he changes the text field and clicks the save button, the OnTextChanged event is firing to update the other values on the page but the OnClick event for the save button is not firing at all. He has to click the save button a second time to get the OnClick event to fire. I tested the same functionality on my machine and it's still working fine for me. He and I are looking at exactly the same page in the same environment with the same database. I had my tester clear his cache etc. The only difference I can find is that my Chrome version is "14.0.835.202 m" while his is simply "14.0.835.202".
Are there any known issues with Chrome and ASP.NET where event firing can be non-deterministic or something? Anyone have any other idea why this might be happening? Thanks for your time!
I believe this is a known issue.
One option is to disable the button (client-side) when the user is typing in the TextBox, and enable it after the TextChanged event completes.
Another option is to remove AutoPostBack="true" and use AJAX instead.

jQuery after onclick

I've a form with different field, a validation summary and a button Sign up!
When I click on Sign up, if a field is empty, it active validation summary and until here there's no problem.
So the problem is that I would want active a jQuery script after it was clicked Sign up button and it appeared validation summary.
I try with
$(this).load(function()
but in effect it occur when the page is load and not after the button is clicked.
I try also use button's onclick ,but I have to use script after onclick and not while.
I used Validation group for all field of form, also button and for this reason it seems doesn't postback!
Um your question is a bit unclear to me but wouldn't this work ?
$("#sign_btn").click(function(){
alert("I was clicked");
});
sign_btn is the ID of the button.

How to Not Submit a Form Using AJAXToolkit AutoComplete Extender?

I have used AJAXToolkit AutoComplete extender in my project.It works fines.But the issue is with the form of the page.
when i type in the AutoComplete, i get list of suggestions.When i click on the page other than the Autocomplete, the form gets submitted.
any suggestions how to stop submission of entire form whenever i click on the page?I use .net 2.0
Does your TextBox have AutoPostBack="True" set? If so, it will automatically postback when you're "finished" (when the input control loses focus). If this is the case, just set it to false.
yeah,My TextBox AutoPostBack was set to true which i have changed it to false, now.
but i have a url attached to each of my suggestions.On click of suggestion, user gets navigated to that particular url. When i do AutoPostback= "false", i wont get navigated to that page.
HOw do i handle it?
I think it would be as simple as adding a required validator to your element to see if the user selected anything.
Eric
Use jquery to add an event handler that detects clicks. When a click occurs, stop the browser. Let me know if you need code.

ASP.NET default button

I have a master page with a search box and button at the top. This search functionality is taking over the "enter" key for all my web forms that use this master page. That is, if I have a login page that uses this master page and the user enters in their username/password and hits "enter", instead of logging in the user the system performs a search.
What's the best way to set up the default submit buttons. I could wrap everything in asp Panels and set the DefaultButton property, but that seems a bit tedious. Is there a better way?
use defaultbutton property of form or panel
<form defaultbutton=“button1” runat=“server”>
<asp:button id=“button1” text=“Same Page” runat=“server”/>
<asp:panel defaultbutton=“button2” runat=“server”>
<asp:textbox id=“foo” runat=“server”/>
<asp:button id=“button2” runat=“server”/>
</asp:panel>
</form>
As you have discovered default buttons can cause issues when there is more than one button on a page. I would take the Geeks suggestion but simplify it by removing the setfocus client script and extend it by adding the keydown event to both the search textbox and the login textboxes such that the enter key fires the correct button depending on if your user is using the search box or the log in box, or any other textbox you want to add the javascript to.
You can set focus on loading the page (in code behind if you like) to save the user some mouse work or tabbing if there is a sensible control for the user to start at, but otherwise the control the user is interacting with should determine the flow of the page and what the enter key does.
set focus on the text box ,
Page.RegisterStartupScript("SetFocus", "< script >document.getElementById('" + TextBox1.ClientID + "').focus();< /script >");
and then
In the keydown event for the last textbox you can do something like this:
If e.KeyCode = Keys.Enter Then
Me.Button1.Select()
End If
Rather than using javascript to manipulate the page you could put the search box and the submit button into an IFRAME on the master page. If the focus is in the iframe clicking will submit the search form, if the user is on your main form within the page they will submit the normal page.
The <iframe> src attribute points to a little self contained aspx page holding your text box and submit button which redirects to your search results form.
This is what we tried on our project which seemed to work. I changed the Search asp:Button to be an asp:LinkButton. I then added some CSS style to give it a background image to make it look like a button. LinkButtons are apparently not used by the page for determining which Button is the default action when pressing Enter. The sweet part was that LinkButton can still have click actions associated with them so I didn't have to change any of my code-behind stuff.

Resources