In the Below code iam trying to get the orginal path of selected folder.I tried the below code it displays C:\fakepath\10_7_DoxTest.tiff but i am selecting from E:\TestProject\10_7_DoxTest.tiff.Pls anyone help me to solve the problem.
<asp:HiddenField ID="hiddenField1" runat="server" />
<asp:Button ID="BtnBatch" onClientClick="document.getElementById('hiddenField1').value = document.getElementById('file').value" runat="server" Text="Create Batch" OnClick="btnCreate_Click" />
<asp:FileUpload ID="file" runat="server" webkitdirectory="true" mozdirectory="true" />
Related
i have the following code
<asp:Panel ID="searchPanel" DefaultButton="searchButton" runat="server">
<asp:TextBox ID="searchBox" runat="server" value=" Search..."></asp:TextBox>
<asp:Button ID="searchButton" runat="server" Style="display: none" OnClick="searchInput" />
</asp:Panel>
<asp:Panel ID="loginPanel" DefaultButton="submitButton" runat="server">
<asp:TextBox ID="username" runat="server" required="required"></asp:TextBox>
<asp:TextBox runat="server" ID="password" required="required"></asp:TextBox>
<asp:Button ID="submitButton" runat="server" Text="Log in" OnClick="login" />
</asp:Panel>
whenever i press 'enter' key when searchBox is focused, in the other panel fields are highlighted and says "Please fill the field".
How can I solve this?
I believe you are using HTML 5 "required" attribute. This will cause validation when you try to do a postback.
You can use a form specific for search control and use "novalidate" attribute in the form element.
Or
You can use validation groups to achieve this.
solved the issue by using validation group
<asp:RequiredFieldValidator ID="RequiredFieldValidator1"
ControlToValidate="username"
ValidationGroup="emailValidationGroup"
runat="Server">
</asp:RequiredFieldValidator>
ValidationGroup="emailValidationGroup" //goes to button
also don't forget to add
<appSettings>
<add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
</appSettings>
to webconfig
I have an input page where i want to create some required fields and some aren't.
That means that at the first part of the form, you can select the date by pressing a button to show a calender to select the desired date, adding users (by pressing a button) and then you add the required text and finally a submit button.
Right now, when I put the required attribute to the input tag, the first two buttons don't work. They don't fire up and it writes that first I need to insert the required items.
How can I remove the connection between those specific buttons and the required inputs?
Thanks, Arkadi.
Code:
<h3> Create New Project</h3>
Users Added: <asp:TextBox ID="TextBox1" runat="server"
ReadOnly="True"></asp:TextBox>
<asp:Label ID="lblAdded" runat="server" Text="Label" >User Was Already Added</asp:Label>
<asp:Label ID="lblNotFound" runat="server" Text="Label" >User Was Not Found</asp:Label>
<br />
<asp:CheckBoxList ID="CheckBoxList1" runat="server" AutoPostBack="true"
OnSelectedIndexChanged="CheckBoxList1_SelectedIndexChanged"></asp:CheckBoxList>
Add User<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /><br /><br />
Project Name: <input ID="txtName" runat="server" required="required" />
Hand Over Date: <asp:TextBox ID="txtHandOverDate" runat="server" ReadOnly="true"></asp:TextBox>
<asp:Button ID="btnSelectDate" runat="server" Text="SelectDate"
OnClick="btnSelectDate_Click" />
<asp:Calendar ID="Calendar1" runat="server" Visible="False"
OnSelectionChanged="Calendar1_SelectionChanged"></asp:Calendar>
Hand Over Form: <input ID="txtHandOverForm" runat="server" required="required"/>
Subject: <input ID="txtSubjectField" runat="server" required="required" />
Project Porpuse <input ID="txtPorpuse" runat="server" required="required" />
Perimiters<input ID="txtPerimiters" runat="server" required="required" />
Comments <textarea id="txtComments" runat="server"></textarea>
<asp:Button ID="Button2" runat="server" Text="Button" OnClick="Button2_Click" />
I found what I wanted, so to all those who will see this:
I just needed to change the type of the button from submit to command, that means adding the attribute UseSubmitBehavior to false.
Thanks for the Answers, this site is great!
The OnClick events run at the server, but the required attrib is preventing the code from being submitted. If you want to run client side (ie javascript) code, then you will need to use the OnClientClick event instead.
After validation failed, I have a problem with controls (dropdownlist or button) that should cause a new postback. I will try to explain it clearly...
The purpose of my page is to save fives dates in a database. The page has the following controls:
Five textboxes, each one containing a date
A reset button (CausesValidation=false) to restore a default date in one of the 5 textboxes
A dropdown list (AutoPostback=true, CausesValidation=false) of predefined templates that applies 5 dates to the 5 textboxes
A button to save the dates to the database
The textboxes can be edited manually. So, when I click the Save button, if the format of the dates is not valid, the validation fails and the save is aborted. The problem is just after that. If I click on the Reset button or select an item in the dropdownlist, the postback is not triggered. If I try again, then it works. Is there a way to make it work the first time after the first validation failed? I tried deactivating the validation on the client-side when changing the selection in the dropdownlist but the postback still does not occur.
Here is the relevant part of the code:
<asp:DropDownList ID="cboScheduleTemplates" runat="server" AutoPostBack="true" CausesValidation="false" />
<asp:TextBox ID="txtDateDelivery1" runat="server" />
<asp:RegularExpressionValidator ID="revDateDelivery1" runat="server" Display="Dynamic" ValidationGroup="Schedule" ControlToValidate="txtDateDelivery1" Text="*" />
<asp:TextBox ID="txtDateYearbookQuantity" runat="server" />
<asp:RegularExpressionValidator ID="revDateYearbookQuantity" runat="server" Display="Dynamic" ValidationGroup="Schedule" ControlToValidate="txtDateYearbookQuantity" Text="*" />
<asp:TextBox ID="txtDateDelivery2" runat="server" />
<asp:RegularExpressionValidator ID="revDateDelivery2" runat="server" Display="Dynamic" ValidationGroup="Schedule" ControlToValidate="txtDateDelivery2" Text="*" />
<asp:TextBox ID="txtDatePersonalizations" runat="server" />
<asp:RegularExpressionValidator ID="revDatePersonalizations" runat="server" Display="Dynamic" ValidationGroup="Schedule" ControlToValidate="txtDatePersonalizations" Text="*" />
<asp:TextBox ID="txtDateDelivery3" runat="server" />
<asp:Button ID="btnSetDefaultDelivery3" runat="server" ValidationGroup="Schedule" CausesValidation="false" />
<asp:RegularExpressionValidator ID="revDateDelivery3" runat="server" Display="Dynamic" ValidationGroup="Schedule" ControlToValidate="txtDateDelivery3" Text="*" />
<asp:Button ID="btnSaveSchedule" runat="server" CssClass="btnAction" Text="Save" ValidationGroup="Schedule" />
<asp:ValidationSummary ID="validationSummarySchedule" runat="server" ValidationGroup="Schedule" DisplayMode="List" />
As suggested in this post, the problem comes from calls to Page_ClientValidate. So I wrapped the client function like this and the problem went away:
function DoPageClientValidate(validationGroupName)
{
var result = Page_ClientValidate(validationGroupName);
Page_BlockSubmit = false;
return result;
}
I have a div in checkout.aspx page. The contents of div are as follows:
<div id="PaymentDetails" runat="server" style="text-align:center" visible="true">
<asp:Label ID="PaymentDetailsLbl" Text="Payment Details:" runat="server" Font-Size="Large"></asp:Label>
<br />
<br />
<br />
<asp:Label ID="UNameLbl" Text="User Name:" runat="server"></asp:Label>
<asp:Label ID="UNameTextLabel" runat="server" Width="150px"></asp:Label>
<br />
<br />
<asp:Label ID="AmountLbl" Text="Amount:" runat="server"></asp:Label>
<asp:Label ID="AmountTextLabel" runat="server" Width="50px"></asp:Label>
<br />
<br />
<asp:Label ID="CCNumberLbl" Text="Credit Card No:" runat="server"></asp:Label>
<asp:TextBox ID="CCNumberTBox" runat="server"></asp:TextBox>
<br />
<br />
<br />
<asp:Button ID="SubmitBtn" runat="server" Text="Submit" OnClick="SubmitBtn_Click" />
<asp:Button ID="ResetBtn" runat="server" OnClick="ResetBtn_Click" Text="Reset" />
<br />
<br />
<asp:Label runat="server" ID="SuccessMessageLabel" ForeColor="Red"></asp:Label>
<asp:Button ID="SoftwareDownloadsBtn" runat="server" Text="Software Downloads" Visible="false"
OnClick="SoftwareDownloadsBtn_Click" />
<br />
<br />
<asp:RegularExpressionValidator ID="CCNumberValidator" ErrorMessage="Credit Card Number: Min 10 and max 16 digits, starts with 3 or 4"
ControlToValidate="CCNumberTBox" runat="server"></asp:RegularExpressionValidator>
</div>
And i try to set the visibility of div as false when the user has not selected any items or the user has deleted all the items from the shopping cart using this code:
else if ((Session["SelectedRowItems"] == null) || (shoppingCartItems.Count == 0))
{
this.Page.FindControl("PaymentDetails").Visible = false;
GridView1.EmptyDataText = "No Items Checked Out";
GridView1.EmptyDataRowStyle.CssClass = "EmptyGridViewContent";
}
But i'm getting the following error:
Object reference not set to an instance of an object.
The detailed screenshot of the error is here
BTW i'm using VS 2008, asp.net/C# and its a web application project
Please help me.
Thanks in anticipation
Using FindControl() to locate PaymentDetails only works if PaymentDetails is part of the root container. That is, it will not recursively search the controls that are children of other controls.
It appears FindControl() is returning null and you get the error when you try and call a method on null.
FindControl() is unnecessary here. Just use PaymentDetails.Visible = false.
If your div is neither is a child page or usercontrol nor master page, then you need not to use FindControl method. Add a runat server tag and access it in the code behind file, using the id.
apsx page:
<div id="myDiv" runt="server" >
// Your html
</div>
aspx.cs:
private void ShowHideDiv(bool status)
{
myDiv.Visible = status;
}
I am helping my daughter build an asp.net website that has an Access database. We are using a DataList with a couple fields inside the ItemTemplate. The one that is giving me trouble is the Hyperlink. The code is below. When the page loads the hyperlink renders like this:
<a id="ContentPlaceHolder1_DataList1_lnk_6" href="#http://www.washingtonfaire.com/#" target="_blank">Washington Midsummer Renaissance Faire</a>
But when I click on the link, it tries to navigate to "http://localhost:1852/BOOMPiratesB/Raids.aspx#http://www.washingtonfaire.com/#"
What are we doing wrong?
Here is our code.
<asp:DataList ID="DataList1" runat="server" DataSourceID="AccessDataSource1">
<ItemTemplate>
<asp:HyperLink id="lnk" runat="server" NavigateUrl='<%# Eval("Link") %>' Target="_blank" Text='<%# DataBinder.Eval(Container.DataItem, "VenueName")%>'>
</asp:HyperLink>
<br />
<asp:Label ID="DateTextLabel" runat="server" Text='<%# Eval("DateText") %>' />
<br />
<asp:Label ID="CityStateLabel" runat="server" Text='<%# Eval("CityState") %>' />
<br />
<br />
</ItemTemplate>
</asp:DataList>
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="~/App_Data/my.mdb"
SelectCommand="SELECT [VenueName], [Link], [DateText], [Season], [DateStart], [CityState] FROM [qpgRaid]">
</asp:AccessDataSource>
I cannot see where the extra # signs are coming from. They don't appear to be in the field in the table.
It's very puzzling. And insight would be most appreciated.
Have a look at this question
I guess you are using an access hyperlink column to store the link. If you convert it to a text column it should start working fine, or you may have to strip the '#'s manually.