C# - Preventing A Button From Responding To 'Enter'?

May 13, 2010

I have a master template that all the pages on my site use. In the template there is an empty panel. In the code-behind for the page an imagebutton is created in the panel dynamically in my Page_Load section (makes a call to the DB to determine which button should appear via my controller). On some pages that use this template and have forms on them, pressing the Enter key fires the click event on this imagebutton rather than the submit button in the form. Is there a simple way to prevent the imagebutton click event from firing unless it's clicked by the mouse? I'm thinking a javascript method is a hack, especially since the button doesn't even exist in the master template until the button is dynamically created on Page_Load (this is ugly since I can't simply do <% =btnName.ClientId %> to refer to the button's name in my aspx page).I tried setting a super-high tabindex for the image button and that did nothing. Also set the button to be the DefaultButton in its panel on the master template but that did not work either. Moreover, I don't want to add a property to all of my pages that use this template (there are hundreds). It would be optimal to find a solution that works globally from my master template.I'll try to show our example here:We have a button on the top of each page in our system that lets you star the page as one of your favorites, sort of a server-side bookmark system. When the page loads it looks to see if the page is one of your favorites or not and then shows a gold star if it is, and a gray star if it is not. Clicking the imagebutton of a star toggles the page favorite status.In my master template (FullMenu.master) I have this panel

<asp:Panel runat="server" ID="pnlFavorite" style="display:inline;"></asp:Panel>

Next there is a class which creates the button and adds it to the panel on the master template:

public void InsertStarButton()
{
CreateStarButton();

[code]....

View 2 Replies


Similar Messages:

Forms Data Controls :: Gridvew Pager Next Button Not Responding?

Sep 22, 2010

I implemented the class from this link below: http://gonzalo.name/blog/and when I click on the next button image in the pager row, it does not go to the next page, same thing happens when I change a number in the text box, it does not respond. I stepped through the debugger and it does go to the onNextClicked event but does not do any thing. I have a custom grid control and the only thing different then the instruction is rather than using the page_int event I am using the gridview1_init event for this linegridview1.pagertemplate = new fancypagertemplate)gv);I was just wondering if some one has successfully used this code before? Or what other steps could I take to debug this issue?

View 2 Replies

Web Forms :: RequiredFieldValidator And Link Button Not Preventing Postback?

Mar 30, 2010

I have one TextBox with RequiredFieldValidator control and LinkButton on my page.

May occur the following situation on this page:

I filled the texbox and clicked the linkbutton is make postback on the server - so all ok.When I not filled the textbox and clicked linkbutton it will show message "Please enter your first name." and no postback will happen but when I filled textbox and click linkbutton I got a PROBLEM : Message "Please enter your first name." goes away (correct), but it doesn't preventing posback.

View 8 Replies

Preventing Reinserting Of Data When Press Browser's Refresh Button?

Jan 28, 2010

I developed a web application in asp.net.I have a module for saving values to database after clicking the button event.Thats working successfully.After that when i clicked the browser's refresh button the values reinserted to the table each time.How can i avoid this .Which is the code for this solution?

View 1 Replies

AJAX :: Modal Popup Extender Preventing Regular Button Click Event?

Jan 6, 2010

So I have a button on form that is supposed to execute some code-behind on a click event. To this button I also connected a Modal Popup Extender, which once you click OK, it goes away. What doesn't happen (and it should) is btnSendContactForm_Click never gets called.

Using the OnOkScript didn't help me either. I have tried setting the OnOkScript property of the extender, by calling a javascript that simulates the button click on the send button, but that only re-calls the modal pop extender, and a never-ending loop results everytime you click OK.

<!-- Send Button, Extender, and Pop Up Panel -->

View 1 Replies

Web Forms :: Trying To Do Is Validate The Input Only When The Enter Button Is Clicked Not The Search Button?

Dec 7, 2010

I have a asp page with tow buttons search adn enter and asp required field validator in it, what I am trying to do is validate the input only when the enter button is clicked not the search button, right now when the search button is clicked it validates and throws an error.

View 2 Replies

Web Forms :: 2.0 - Set Focus To A TextBox While Button Click Event Is Fired Using Default Button When Enter Key Is Pressed

Mar 25, 2010

How can I set Focus to a TextBox while Button click event is fired using Default Button when enter key is pressed. Here is my Page and code.

<%@ Page Title="" Language="C#" MasterPageFile="~/mpChat.master" AutoEventWireup="true" CodeFile="FocusTest.aspx.cs" Inherits="FocusTest" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Panel ID="Panel1" runat="server" DefaultButton="Button1">
<asp:TextBox ID="TextBox1" runat="server">
</asp:TextBox>
<asp:Button ID="Button1"
runat="server" Text="Button" onclick="Button1_Click" />
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
using System;
public partial class FocusTest : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
TextBox1.Focus();
}
protected void Button1_Click(object sender, EventArgs e)
{
TextBox1.Text = "";
TextBox1.Focus();
}
}

View 1 Replies

Web Forms :: How To Set Enter Key As Default Key For Particular Button

Dec 7, 2010

i have a page with search text box and button ,, when i search by clicking on the button with mouse its working fine But when i am enter the keywords and hitting enter the page getting reloaded.. can have solution for this.

View 2 Replies

Set Button Focus Off When Pressing Enter

Dec 2, 2010

i am using master page i have in my left menu there is a button to logout on the left menu when i click on it i was typing inside a textbox and but whenever i press Enter it logs me out i think because it s causing the click on buttonlogout how to avoid this problem in all my pages but i don t want to disable the press enter only i need to stop it on log outbutton from left menu it seems i have to set focus off on this button.

View 8 Replies

Specific Button Click With Enter?

Sep 4, 2010

i want a specific button be pushed and go to the sub that handles this button click when enter is pushed can be that done?

View 7 Replies

Web Forms :: Enter Button Does Not Work?

Dec 24, 2010

I have a "contact us" page that I am working on. It works fine when you click the Submit button with a mouse. However, nothing happens when I press the "enter key". I have the page wrapped in a panel, with btnSubmit selected as the default button. How do I make the "enter key" work when pressed? Here is the code:

[Code]....

View 2 Replies

Button Onclick Event With The Enter Key Press?

Mar 25, 2010

Have a form with a button and some text fields on it.When I hit enter after filling a field the event for the button fires up event onClick.How can I get around this since on one of the fields I have a textchangeEvent I to fire up.

View 5 Replies

Enter Button Navigates Page Back?

Jul 6, 2010

I have a search field (text box) at the top of my page. When you type something, and press enter, the page navigates back to the previous page? What I want it to do is act as if I clicked the Search button.

View 5 Replies

Webforms - Search Field Enter Button

Feb 10, 2011

I have a web page with 3 search fields on it, each with a different submit button. When using the enter button on the keyboard to submit any of them, an incorrect action is being performed, although with the mouse it's fine. Any ideas why this is happening? The rendered HTML as requested below:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="ctl00_ctl00_Head1">
<body id="home">
<form name="aspnetForm" method="post" action="history_lookup.aspx?theme=t2" id="aspnetForm">
<div>
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTE1MzkzOTQxNDBkGAEFHl9fQ29udHJvbHNSZXF1aXJlUG9zdEJhY2tLZXlfXxYFBSZjdGwwMCRjdGwwMCRNaW5pQ2FydFRleHQxJEltYWdlQnV0dG9uMQUsY3RsMDAkY3RsMDAkVG9wTmF2JFF1aWNrU2VhcmNoMSRJbWFnZUJ1dHRvbjIFLGN0bDAwJGN0bDAwJFRvcE5hdiRRdWlja1NlYXJjaDEkSW1hZ2VCdXR0b24xBShjdGwwMCRjdGwwMCRjcGhSb290JGNwaFN1Yk1hc3RlciRzdWJtaXQxBShjdGwwMCRjdGwwMCRjcGhSb290JGNwaFN1Yk1hc3RlciRzdWJtaXQy4UTdoX+Ej1GFsXGOrI898SMftDA=" />
</div>
<script type="text/javascript">
//<![CDATA[
var theForm = document.forms['aspnetForm'];
if (!theForm) {
theForm = document.aspnetForm;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
//]]>
</script>
<script src="/WebResource.axd?d=gfGwAOwAxcQ9Nlq6l3EJfg2&t=634166396192656250" type="text/javascript"></script>
<div>
<input type="hidden" name="__PREVIOUSPAGE" id="__PREVIOUSPAGE" value="fwZ-2v_x8CYGGr9a8Ce0s6gkE38QmubHNljKJaKxZV41" />
<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWCAKs3Nu8DwLV2a2zBwKK/6PwCQLBpvyBBAKT+aizBgL+qMTTDwLU1/SWCwL+qNiuCArtGFkuC9Zj3X3If1cwPC7PKtcm" />
</div>
<div class="container clearfix" style="left: 0px; top: 0px">
<div class="utilityNav">
<a class="MenuItem" href="/extranet.aspx?theme=t2" title="Account Info">
Account Info
</a>
|
<a class="MenuItem" href="/history_lookup.aspx?theme=t2" title="Order History">
Order History
</a>
|
<a class="MenuItem" href="/_user_logout.aspx" title="Sign Off">
Sign Off
</a>
</div>
<div class="header">
<div class="cart" >
<div id="menu">
<div class="cartimage">
<input type="image" name="ctl00$ctl00$MiniCartText1$ImageButton1" id="ctl00_ctl00_MiniCartText1_ImageButton1" src="images/bg-cart-corner.gif" align="left" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$ctl00$MiniCartText1$ImageButton1", "", false, "", "cart.aspx", false, false))" style="border-width:0px;" />
</div>
<div class="cartlabel">Checkout Cart:<br />
<a id="ctl00_ctl00_MiniCartText1_lbMiniCart2" class="cartlink" href="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$ctl00$MiniCartText1$lbMiniCart2", "", false, "", "cart.aspx?theme=t2", false, true))">View your cart</a>
</div>
<br /><br />
</div>
</div>
</div>
<div class="primaryNav">
<div class="navdropdown">
</div>
<div align="right" class="quicksearch">
<div class="QuickSearch">
<div id="ctl00_ctl00_TopNav_QuickSearch1_quicksearchpanel" onkeypress="javascript:return WebForm_FireDefaultButton(event, 'ctl00_ctl00_TopNav_QuickSearch1_ImageButton1')">
<table cellpadding="0" cellspacing="0" class="QuickSearch">
<tr>
<td class="quicksearch_text">
<span id="ctl00_ctl00_TopNav_QuickSearch1_lblSearch"></span>
</td>
<td >
<input class="QuickSearch" type="text" name="searchstring" size="15" maxlength="30" value="Search" onfocus="if (this.value == 'Search') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Search';}" />
</td>
<td class="quicksearch_button">
<input type="image" name="ctl00$ctl00$TopNav$QuickSearch1$ImageButton2" id="ctl00_ctl00_TopNav_QuickSearch1_ImageButton2" src="images/searchbutton.gif" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$ctl00$TopNav$QuickSearch1$ImageButton2", "", false, "", "/Searchdh.aspx?theme=t2", false, false))" style="border-width:0px;" />
</td>
</tr>
</table>
</div>
</div>
</div>
</div>
<td valign="top">
<div class="HistoryLookupPage">
<h1 class="PageHeader">
<span id="ctl00_ctl00_cphRoot_cphSubMaster_PageHeader1_LabelHeader">Order History</span>
</h1>
<p>
Enter the reference number of the order you want to see.
</p>
<p>
Reference number
<input name="ctl00$ctl00$cphRoot$cphSubMaster$CustomerReference" type="text" id="ctl00_ctl00_cphRoot_cphSubMaster_CustomerReference" class="borderTextBox" />
<input type="image" name="ctl00$ctl00$cphRoot$cphSubMaster$submit1" id="ctl00_ctl00_cphRoot_cphSubMaster_submit1" src="images/buttons/findorder-blue.gif" style="border-width:0px;" />
</p>
<br />
<p><b>Or search by PO Number</b></p>
<p>
<input name="ctl00$ctl00$cphRoot$cphSubMaster$CustomerReference2" type="text" id="ctl00_ctl00_cphRoot_cphSubMaster_CustomerReference2" class="borderTextBox" />
<input type="image" name="ctl00$ctl00$cphRoot$cphSubMaster$submit2" id="ctl00_ctl00_cphRoot_cphSubMaster_submit2" src="images/buttons/findorder-blue.gif" style="border-width:0px;" />
</p>
</div>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
and the aspx markup
<%@ Import Namespace="System.Configuration.ConfigurationManager" %>
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="history_lookup.aspx.vb"
EnableViewState="false" Inherits="history_lookup" ValidateRequest="false" CodeFileBaseClass="Main.Page"
MasterPageFile="~/masters/default/main.master" RuntimeMasterPageFile="ThreeColumn.master"
CrumbName="<%$ Resources: Language, LABEL_MENU_HISTORY %>" %>
<%@ Register Src="~/controls/Message.ascx" TagName="Message" TagPrefix="uc1" %>
<%@ Register Src="~/controls/PageHeader.ascx" TagName="PageHeader" TagPrefix="uc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="cphSubMaster" runat="Server">
<td valign="top">
<div class="HistoryLookupPage">
<uc1:Message ID="Message1" runat="server" />
<uc1:PageHeader ID="PageHeader1" runat="server" Text="<%$ Resources: Language, LABEL_MENU_HISTORY %>"
EnableTheming="true" />
<p>
<asp:Literal ID="Literal1" runat="server" Text="<%$ Resources: Language, LABEL_PLEASE_ENTER_ORDERREF %>"></asp:Literal>
</p>
<p>
<asp:Literal ID="Literal2" runat="server" Text="<%$ Resources: Language, LABEL_HISTORY_LOOKUP %>"></asp:Literal>
<asp:TextBox runat="server" ID="CustomerReference" CssClass="borderTextBox" />
<%-- <asp:Button ID="Button1" runat="server" CssClass="BtnC" Text="<%$ Resources: Language, ACTION_LOOKUP %>" />
--%> <asp:ImageButton ID="submit1" runat="server" imageurl="~/images/buttons/findorder-blue.gif" />
</p>
<% if Not globals.User("Anonymous") then %>
<br />
<p><b>Or search by PO Number</b></p>
<p>
<asp:TextBox runat="server" ID="CustomerReference2" CssClass="borderTextBox" />
<%-- <asp:Button ID="Button2" runat="server" CssClass="BtnC" Text="Find Order" />
--%> <asp:ImageButton ID="submit2" runat="server" imageurl="~/images/buttons/findorder-blue.gif" />
</p>
<% end if %>
</div>
</td>
</tr>
</table>
</asp:Content>

View 1 Replies

How To Enter Key Triggers Wrong Submit Button

Feb 23, 2011

I am working on an mvc application. Two tables each have their individual submit button. Table1 has default submit on enter key. How do I change the submit button based on textbox focus?

<table>
...<td align="left"><%= Html.TextBox("name")%></td>
...<input id="nameSubmit" name="NameSubmit" type="submit" value="Search"/>
</table>
<table>
...<td align="left"><%= Html.TextBox("idNum")%></td>
...<input id="idSubmit" name="IdSubmit" type="submit" value="Search"/>
</table>

I tried using the panel, but "the DefaultButton of 'Panel1' must be the ID of a control of type IButtonControl".

View 1 Replies

Enter Key Press For Submit Button Click?

Mar 24, 2011

I have an AJAX PopupExtender that popsup a panel with submit button. I want to recognise the enter key press as the click event for the submit buttNeed to set the form property called "AcceptButton" to this button to achieve this functionality. I have two popups with a submit button on each of them. How to set this behaviour ?

View 3 Replies

Defaultbutton - Enter Key In C# Firing Wrong Button?

Aug 12, 2010

I have a text box and many buttons. When user is in some text box and presses the "enter" key then specific button click event is raised. I read on the internet that there are some problems with the "enter" key and I tried few solutions but still it always enters that button event (that button is the first button in the page).

I tried creating a button which does nothing and writing this in the page_load:

idTextBoxFA.Attributes.Add("onkeydown","if(event.which || event.keyCode){if ((event.which == 13) || (event.keyCode == 13)) {document.getElementBtId('" + noEnterButton.UniqueID + "').click();return false;}} else {return true}; ");

All my page controls are in a form and I tried giving the form "defaultButton" property to that button I created. That didnt work either.

View 1 Replies

User Controls :: How To Use Enter Key Instead Of Button For Search

May 7, 2015

Instead of clicking button ,How Enter Key Works??

Type Something in TextBox and Press Enter and result appear without Clicking any button , How??

View 1 Replies

Web Forms :: Enter Key Button Press Not Working In FireFox?

Jan 17, 2010

I have to set enter key event to text box, it work fine in IE, but not in firefox.

Here my code:

function DoClickToButton() {
var keycode = (event.keyCode ? event.keyCode : (event.which ? event.which : event.charCode));
alert(keycode);
if (keycode == 13) {
document.getElementById('<%=Button1.ClientID %>').click(); return false;
}
else {
return true
};
}

View 6 Replies

Web Forms :: Allow User To Press Enter Key To Select Button?

Jan 15, 2010

[Code]....

View 8 Replies

Web Forms :: On Enter Key Press Button Click Should Fire?

May 18, 2010

How can one fire a button click event when someone presses Enter in Textbox. I had a master page on which Search button & a Textbox for writing Search text is there. When one clicks on "Search" button, it works fine. But when one presses Enter, no search results are displayed.

View 3 Replies

Adding Javascript So It Would Recognize The Button And Allow Users To Hit Enter

Mar 1, 2010

I am having trouble with something, my client wants to be able to hit <enter> as well as click the button on this page:-

[URL]

If you look at the Blue "Postcode search" and try searching for a nursery byb clicking the button you will see how it works. However then try doing the same but hitting <enter> and see what happens..

The front end html is as follows:-

PHP Code:

[code]....

I tried adding javascript so it would recognize the button and allow users to hit enter but this did not work.

View 7 Replies

Web Forms :: Set Enter Key Button For Gridview Footer Template?

Sep 7, 2010

[URL]

I have used the above grid view in my application ... Its working good, no problem.

Upon clicking the Addnewrowbutton, it uses to create a new row dynamically.

What i need is, new row should also be created dynamically, upon pressing enter key in the last textbox on a particular gird view row. User always can't go and click addnewrowbutton every time to create new row. Instead of it, user can press enter in the last textbox on a particular grid view row to create new row.

View 2 Replies

C# - How To Fire A Button Click Event When Enter Key Is Pressed

Jul 14, 2010

I have a form with several submit buttons. I would like the button's click events to fire when enter is pressed based on which textboxes currently have focus. I am able to specify one button using the code below by adding the onkeydown event to the body of the page and checking for Enter's keyCode

<body onkeydown="if(event.keyCode==13){document.getElementById('btnSearch').click();}">
</body>

I assume this code can be modified or call a function to perform a conditional to see if txtSearch or txtSubmit has focus and specify btnSearch or btnSubmit accordingly, but I am not experienced with javascript.

View 3 Replies

Trying To Let A User Enter The Name Of A Website In A Textbox And Click On A Button?

Feb 22, 2011

I'm trying to let a user enter the name of a website in a textbox and click on a button. When the button has been clicked the website URL should be sent to a method which will use a WebBrowser to navigate to the website and take a screenshot of it. Further it should afterwards grab this screenshot and generate a thumbnail of it.

... And the tricky part

The tricky thing is that according to MSDN the System.Drawing should not be used in neither Windows or ASP.NET services, which leaves me with 2 approaches:

Ignore the MSDN and implement the class which contains the necessary methods.

Create a WCF Service with the necessary methods.

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved