Detecting Enter in TextBox ASP.NET no JavaScript Please - asp.net

Basically I have a Search Text Box with a LinkButton Control on which the click event is fired. now what i want is when the user type keywords and press enter the Click event got fired.
So No Javascript Only ASP.NET With VB.NET v2.0
Sincerely
Rajeev
Rajeev_rsd#hotmail.com

Create a Panel that contains both the TextBox and LinkButton. The Panel has a property called DefaultButton, set DefaultButton equal to the ID of the LinkButton.
<asp:Panel id="panel" runat="server" DefaultButton="linkButton">
<asp:TextBox id="search" runat="server"/>
<asp:LinkButton id="linkButton" runat="server"/>
</asp:Panel>

Can you not just use AutoPostback on the textbox?

Related

Asp.Net multiple submit buttons, enter submits only the first

I have a few submit buttons in my ASP.NET page. Everything works fine, but when a user hits enter button always the first submit button works. I want to fire each submit button with corresponding fields but cannot have multiple forms. Is it possible to group them without using forms?
You don't need forms, just wrap the related controls in their own panels and use the Panel.DefaultButton property.
Use the DefaultButton property to indicate which button gets clicked
when the Panel control has focus and the user presses the ENTER key.
The DefaultButton can be set to the identifier for a Button control or
any control that implements the IButtonControl interface except a
LinkButton control.
Please use DefaultButton property like this
<asp:Panel runat="server" DefaultButton="bt1">
<asp:TextBox runat="server" />
<asp:Button id="bt1" Text="Default" runat="server" />
</asp:Panel>
Please refer here :- ASP.NET DefaultButton Property

ASP.Net Label control's Text property not updating text under button click event

I have developed a small application in SharePoint. I am using custom application page and load .ascx Control over that page under Page_Load() method. In .ascx Control, I have created a small form with text boxes and a button Control. under this button click event, I want to change the text property of label like: lblConfirmation.Text = "Confirmation is OK"; but it did not change the text. It shows nothing because i set text property empty in label Control.
<asp:Label ID="lblConfirmation" runat="server" Text="" ></asp:Label>
Any Idea, what is wrong ?
What are this single quotes in your asp:Label definition ? please check this
<'asp:Label ID="lblConfirmation" runat="server" Text="" ><'/asp:Label>
it must be replaced by
<asp:Label ID="lblConfirmation" runat="server" Text="" ></asp:Label>
Try to debug the code in your visual studio and let us know if you get any error ?
Thanks

ajax and asp.net OnClick clash

I have a OnClick even on a image button and also a AJAX modualPopupExtender (from the ajax toolkit) the problem i have is that when i have the ModalPopupExtender acting on the image button it doesent fire the onClick event on the imageButton hers the code i have:
<ItemTemplate>
<asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" CancelControlID="btnCancel"
TargetControlID="Image1" PopupControlID="Panel1" BackgroundCssClass="ModalPopupBG">
</asp:ModalPopupExtender>
<asp:ImageButton ID="Image1" OnClick="ImageButton_Click" runat="server" ImageUrl="~/images/Upload-icon.png" />
</ItemTemplate>
when i have this code the panel does popup but doesn't fire the onClick event, if i take out the ajax extender it fires the onclick event is they any way i can have both?
Thanks in advance.
Put another button with a CSS class so it doesn't show on the page (or style="display:none;" don't use visible=false or it won't work).
Then make the TargetControlID of your Modal Popup Extender to be your fake button.
Now you can handle the Click event of the ImageButton normally in your code behind, after doing the code that you want, call
ModalPopupExtender1.Show()
to show the popup.

Using Validation controls with a GridView

A typical situation:
In my GridView control, I have a Footer row which contains a Textbox and an "Add" Button. When the button is pushed, the Text entered in the TextBox is added to the grid. I also have a validation control to require that, when the button is pushed, that text has been entered in the TextBox. After a new row is added, the textbox is clear to allow for easy entry of the next item.
The user may also edit the text in previously entered rows by clicking the Edit LinkButton, which puts the row into edit mode. Clicking an Update LinkButton commits the change.
The problem:
When, I click the Update link to commit the changes, if text has not been entered in the Footer row's TextBox (the row used to add a new entry), the validation control returns a "Entry Required" error. It should only require an entry if the Add button is pushed, not if the Update LinkButton is pushed.
It seems that the server side Validation control's validating event fires before the GridView's RowCommand event or the btnAdd_Click event, so I am wondering how, from the server, I can determine what event fired the postback so I can determine whether what edits should be performed for the given situation.
I am using a mix of client side "required" validation edits as well as more complex server sides. Since I probably have to have some server sided validations, I would be happy with just knowing how to handle server sided validations, but really, know how to handle this situation for client validations would also be helpful.
Thanks.
Convert your CommandField into a TemplateField, and in the EditItemTemplate, change the Update LinkButton's CausesValidation property to false.
Update:
Converting to a TemplateField is simple and doesn't require any code changes (just markup):
Changing the CausesValidation property to false in the markup is also straightforward:
<asp:TemplateField ShowHeader="False">
<EditItemTemplate>
<asp:LinkButton ID="lnkUpdate" runat="server" CausesValidation="False"
CommandName="Update" Text="Update"></asp:LinkButton>
<%--
More controls
--%>
</EditItemTemplate>
<ItemTemplate>
<%--
Controls
--%>
</ItemTemplate>
</asp:TemplateField>
Now, if you want your footer and data rows to be validated separately, you need to use validation groups, which is explained in Microsoft's documentation. All the controls in the same validation group will have their ValidationGroup property set to the same value, like this:
<asp:LinkButton ID="lnkUpdate" runat="server" CausesValidation="True"
CommandName="Update" Text="Update" ValidationGroup="GridViewDataRowGroup">
</asp:LinkButton>

RequiredFieldValidator doesn't work when submitting form after Posting back by TextChanged event to the Textbox

In my .aspx form I have a text box with Autopostback=True.
I also set a RequiredFieldValidator next to it. But when Posting back by TextChanged event of my text box, my RequiredFieldValidator appears but still I can submit my form with nothing in the text box!
What is wrong, and how can I fix this?
You have to set the textbox's CausesValidation property to true (it's set to false by default for textboxes).
Give both the text box and the submit button the same validation group.
try this code
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ErrorMessage="*" ForeColor="Red" ControlToValidate="TextBox2" Display="Dynamic" runat="server" />
<asp:Button ID="btn" Text="button" CausesValidation="true" runat="server"/>
and make sure that ControlToValidate="" has same name as the <asp:texbox/>has
the best way to do is just right below TextBox field type <asp:Required and when the options come just pres TAB Button twice

Resources