I found, on simple form in ASP.NET page I can submit its values by pressing enter key by including form fields into Panel control and set up its default button.
But how can I do this for DetailsView? I want to submit by insert button on inserting and update button on updating.
You can try with DefaultButton property (Default Submit Button)
<asp:Panel ID="panel1" runat="server" defaultbutton="Button1">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button1" OnClick="Button1_Click" />
</asp:Panel>
Link : http://msdn.microsoft.com/fr-fr/library/system.web.ui.webcontrols.panel.defaultbutton.aspx
You can also define AccessKey property
Link : http://msdn.microsoft.com/fr-fr/library/system.web.ui.webcontrols.webcontrol.accesskey.aspx
Related
This is my aspx code:
<asp:TemplateField HeaderText="Enter_Quantity" >
<ItemTemplate>
<asp:TextBox ID ="TextBox1" runat="server" DataField="Total_Quantity" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1" ErrorMessage="Please add a quantity"> </asp:RequiredFieldValidator>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID ="Button7" runat="server" OnClick="Button7_Click" CommandArgument="Button7" CommandName="Select" Text="Add To Cart" CausesValidation ="true" />
</ItemTemplate>
</asp:TemplateField>
Kindly note that the Button is in every Gridview Row and also the textbox column is in every Gridview row.
The problem I'm facing is that when I keep the textbox empty and then click on the button. It is showing the error message "Please add a quantity". But it is showing it in every Gridview row. I want to show this error message for that specific GridView row.
How do I solve this ?
Can someone correct my aspx code ?
Set CauseValidation = "false".
It allows you to remove validation from specific control. Suppose you're using two buttons in your page but you want only one button to validate. But as per ASP rules all button will validate your form because of CausesValidation = true by default.
I have an asp panel in page which have many input filed like(textbox,checkbox,select etc)
and two button one for saving(btnSave) the form and the second is for cancel(btnCancel) purpose, and the btnSave is the default button of panel.
The problem occurs when the cancel key get the focus and user press the Enter key, then the default key of asp panel which in this case is save button fire.
<asp:panel DefabultButton="save">
<asp:textbox id="someid" runat="server"></asp:textbox>
<asp:textbox id="someid2" runat="server"></asp:textbox>
<asp:textbox id="someid3" runat="server"></asp:textbox>
<asp:textbox id="someid4" runat="server"></asp:textbox>
<asp:button id="btnSave" run="server" value="Save" />
<asp:button id="btnCancel" run="server" value="Cancel" />
</asp:panel>
is there any way to prevent the default key firing on cancel key Enter press.
I have a page which consists of a form on top to add new records into table1 and below that a GridView which shows records in table1 with the ability to edit.
Now the form above is simply one text box which allows you to enter names into table1, this textbox has a required field validator. The validator causes issues however when the gridview is in edit mode as when the user presses 'update' nothing is saved because the validator is triggers (as there is nothing in the form above)
How can I fix this?
You have to put CausesValidation="False" in GridView
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" CausesValidation="False"/>
You can set the RequiredFieldValidator Control and the Add button have the same ValidationGroup name. Something like this:
<asp:Button ID="btnAdd" runat="server" OnClick="btnAdd_Click" ValidationGroup="addValidation" />
<asp:RequiredFieldValidator ID="nameRequired" ControlToValidate="txtName" runat="server" ValidationGroup="addValidation"></asp:RequiredFieldValidator>
...
<asp:Button ID="btnUpdate" runat="server" OnClick="btnUpdate_Click" />
So that, the Update button won't be impacted.
Use cause validation to false in the gridview button.
<asp:Button ID="Button2" runat="server"
CausesValidation="False"
Text="Cancel - Will Not Validate!" />
Here is an example:
http://www.java2s.com/Code/ASP/Asp-Control/CausesValidationFalse.htm
I have a lot of textboxes on submit page and all have a validator. I want to control them with a submit button which is on master page. It works but other buttons also cause validation. validation summary is always shown either submit button is clicked or any other buttons. how can I control this situation? (asp.net)
for each individual submit use "ValidationGroup". here is the sample:
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ControlToValidate="TextBox1" ValidationGroup="Submit" ID="RequiredFieldValidator1" runat="server" ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ControlToValidate="TextBox2" ValidationGroup="Submit" ID="RequiredFieldValidator2" runat="server" ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>
<asp:Button ID="Button1" ValidationGroup="Submit" runat="server" Text="Button" />
I think you can resolve this by using ValidationGroup Property..
http://msdn.microsoft.com/en-us/library/ms227424.aspx
http://www.w3schools.com/aspnet/prop_webcontrol_imagebutton_validationgroup.asp
Thanks
Deepu
I said in my last question and will say in this one too, basically my username reflects my experience!
I currently have a page with 2 listviews, one of which has a number of controls in the InsertItem template.
One of these controls in particuilar is a DDL and I have a Modal Popup Extender hooked up to it. I want to trigger the MPE only when a particular value(not index) is selected. Here is where I am up to now!
DropDownList ExpenseTypeDDL =
(DropDownList) Expenses.InsertItem.FindControl("ExpenseTypeDDL");
int ExpenseType = (Int32.Parse(ExpenseTypeDDL.SelectedValue.ToString()));
if (ExpenseType == 1)
{
AjaxControlToolkit.ModalPopupExtender mpeMiles =
(AjaxControlToolkit.ModalPopupExtender)Expenses.InsertItem.
FindControl("mpeMiles");
mpeMiles.Show();
}
Above are the contents of the DDL SelectedIndexChanged event. This DDL is based on expense types, I want to target a particular value (db primary key) and then display the modal popup so the user can enter their mileage then do some other stuff after.
Here is my mpe
<cc1:ModalPopupExtender ID ="mpeMiles" TargetControlID ="ExpenseTypeDDL"
runat="server" DropShadow="true" PopupControlID="pnlMiles"
BackgroundCssClass="modalBackground" />
<asp:Panel CssClass="modalPopup" ID="pnlMiles" runat="server"
Height="170px">
<div style="padding: 5px; text-align:center">
<asp:Label ID="lblStart" runat="server">Start location.</asp:Label>
<asp:TextBox ID="txtLocationStart" runat="server" />
<asp:RequiredFieldValidator ID="reqLocation" runat="server"
ErrorMessage="You must enter a start location"
ControlToValidate="txtLocationStart" Display="Dynamic" Text="*" >
</asp:RequiredFieldValidator>
<asp:Label ID="lblDestination" runat="server">Destination.</asp:Label>
<asp:TextBox ID="txtDestination" runat="server" />
<asp:RequiredFieldValidator ID="reqDestination" runat="server"
ErrorMessage="You must enter a destination"
ControlToValidate="txtDestination" Display="Dynamic" Text="*" >
</asp:RequiredFieldValidator>
<asp:Label ID="lblMiles" runat="server">Please enter your Mileage</asp:Label>
<asp:RequiredFieldValidator ID="reqMileage" runat="server"
ErrorMessage="You must enter your mileage" ControlToValidate="txtMiles"
Display="Dynamic" Text="*" ></asp:RequiredFieldValidator>
<asp:TextBox ID="txtMiles" runat="server" />
<br />
<br />
<asp:Button ID="btnMiles_OK" runat="server" Text="Save"
CausesValidation="false" />
<asp:Button ID="btnMiles_Cancel" runat="server" Text="Cancel"
CausesValidation="false"/>
</div>
</asp:Panel>
At the moment the mpe shows as soon as the DDL is clicked, but I want that to happen only for the selected value of 1.
Can someone please tell me what I am doing wrong?
TIA
dotnetnewb
This is happening because you have set up the DDL as target of your modal popup extender - so whenever target index is changed, the dialog is shown. The solution is to have an hidden button and make that a target control for modal popup extender - if your DDL has auto-postback as true then your server side code will check the selected index and popup the dialog.
From user experience perspective, unless you have UpdatePanel on page, this would mean on DDL change, page will refreshed and a dialog will be shown. You can also use modal pop-up javascript API to show/hide on DDL selected index change w/o doing post-back. For example,
$find('mpeMiles').show();