|
My guess is you do not return from the function if the validation fails.
But it would be nice, if you can post your code so that exact problem can be looked upon.
Manas Bhardwaj
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
Here is the code:
<tr><td><asp:FileUpload ID="DocumentFileUpload" runat="server" />
<asp:Button ID="DocumentUploadButton" runat="server" OnClick="DocumentUploadButton_Click"
Text="Upload" Height="21px" Width="80px" /></td>
</tr>
<tr><td><asp:CustomValidator ID="DocumentUploadedCustomValidator" runat="server" Display="Dynamic" CssClass="labeltext"
ErrorMessage="<"Document must be uploaded %>"
OnServerValidate="DocumentUploadedCustomValidator_ServerValidate" ></asp:CustomValidator>
<asp:RegularExpressionValidator ID="DocumentUploadExpressionValidator" runat="server" CssClass="labeltext"
ControlToValidate="DocumentFileUpload" Display="Dynamic"
ErrorMessage="<"Only PDF or Word files is allowed."%>"
ValidationExpression="[a-zA-Z\\].*(.doc|.DOC|.docx|.DOCX|.pdf|.PDF)$"></asp:RegularExpressionValidator>
</td>
</tr>
protected void DocumentUploadedCustomValidator_ServerValidate(object source, ServerValidateEventArgs args)
{
CustomValidator cv = (CustomValidator)source;
args.IsValid = !String.IsNullOrEmpty(System.Convert.ToString(ViewState["DocumentFileId"]));
}
protected void DocumentUploadButton_Click(object sender, EventArgs e)
{
PDFFilename = Path.GetFileName(DocumentFileUpload.PostedFile.FileName);
int FileExtensionIndex = PDFFilename.IndexOf(".");
PDFFilename = PDFFilename.Substring(0, FileExtensionIndex);
PDFFilename += ".pdf";
ViewState["PDFFilename"] = PDFFilename;
Guid g = AddFile(DocumentFileUpload.FileBytes, PDFFilename);
File.Delete(PDFSaveLocation);
ViewState["DocumentFileId"] = g;
DocumentUploadedCustomValidator.IsValid = true;
if (ViewState["DocumentFileId"] != null)
{
DocumentUploadedLabel.CssClass = "SuccessMessagesLabel";
DocumentUploadedLabel.Text = "Document Uploaded Successfully";
}
else
{
DocumentUploadedLabel.CssClass = "ErrorMessagesLabel";
DocumentUploadedLabel.Text = "Document Upload Failed";
}}
Success is the good fortune that comes from aspiration, desperation, perspiration and inspiration.
|
|
|
|
|
Hey man... are you using windows apps (OpenFileDialoge) or web app HTML File input?
|
|
|
|
|
Hi ,
i want to specify the maximum number of digits for numeric part and the Decimal part in a text box.
i tried specifying precision and maxlength of the text box but then it if we input the max length then the precesion cannot be inputted and it gets resetted to the maxamount which should not be possible.
like if Maxlength=8
precsion = 2
input required:123456.90 possible
input required : 12345678.89 which is not possible
so is there any way we could specify the format of the numeric part and as well the decimal part. which would restrict for only that particular input format.
like : dddddddd.dd
thanks in advance....
cheers,
sriharsha
|
|
|
|
|
You can use regular expressions to do the validation.
In between, do you how to build a regular expression for this?
Manas Bhardwaj
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
hi,
but what is the validation expression we need to give for it.
i tried giving
<asp:regularexpressionvalidator id="regexpName"
runat="server"
errormessage="This expression does notvalidate." controltovalidate="TextBox5" validationexpression="^\d\d\d\d.\d\d$">;
but does not work properly.
Thanks and Regards,
sriharsha
|
|
|
|
|
Hi,
you want the same ?
string strD= 1000.1234;<br />
int dI =strD.indexof(".");<br />
string DecimalVal=strD.substring(dI,dI+1);<br />
<br />
string strVal=strD.substring(0,dI);
Hope it will help you..
Thanks,
Sun Rays
To get something you must have to try once.
My Articles
|
|
|
|
|
hi,
actually i want to fix the max length of numric part and the decimal part.
thanks and regards,
sriharsha
|
|
|
|
|
Hi ,
I used Regularexpression and its working fine.
as:
<asp:regularexpressionvalidator id="regexpName" runat="server"
errormessage="This expression does not validate."
controltovalidate="TextBox5"
validationexpression="^\d{1,8}(\.\d{1,2})?$" enableviewstate="true">;
in
controltovalidate : speicfy the textbox to validate
ValidationExpression: which validates the expression in the format (8,2)
otherwise gives error.
Thanks for all suggestions.
sriharsha
|
|
|
|
|
Hello Guys,
My question is,
Is it possible to develop user defined ajax based & callback based web control in ASP.NET 2.0 just like as Update Panel Control.If yes then how is it possible to achieve it.Please tell me about this.
Thanks in adavance,
-Vijay.
|
|
|
|
|
Dear All
My Web-Application works very fine, but some time say 2-3 in 100 it give an error for
sql server 2005 remote connection not allowed
So what could be the reason and how to solve the same.
Thanks
Yogesh Agarwal
|
|
|
|
|
Which version of SQL Server are you using ? The server is local server or Network server ?
|
|
|
|
|
Thanks for the reply
I am using sql server 2005 and it is a network server, available on my webserver, shared hosting.
Thanks
|
|
|
|
|
Hi,
try doing this steps again.
try[^]
Thanks,
Sun Rays
To get something you must have to try once.
My Articles
|
|
|
|
|
In my application I want to search a file by name from a directory programatically.How to achieve this?
|
|
|
|
|
Try this code
public void test()
{
DirectoryInfo dir = @"c:\test\";
FileInfo[] files = dir.GetFiles();
foreach (FileInfo f in files)
{
string filename = f.Name;
if (filename == "index.aspx")
{
f.Delete();
}
}
}
Regards,
Karthik K...
|
|
|
|
|
can we update gridview column which is visible from database after click on linkbutton.
please say how?
|
|
|
|
|
please make your question a little bit clear so that our experts can answer correctly......
|
|
|
|
|
|
I want my gridview to display one row of the returned data source table. Is this possible?
ML Lingwati
|
|
|
|
|
Yes,it is possible...
Exactly what do you want?
|
|
|
|
|
kumar_k508 wrote: Yes,it is possible...
Exactly what do you want?
I want to display one question at a time from the Questions table in my database.
ML Lingwati
|
|
|
|
|
Please post your question little bit clear...
and as per my understand you want to fetch only one record from your table,
for that,
you have to write a query to fetch the particular one record according to your requirement...and bind it to your gridview...
Cheers
S Kumar
|
|
|
|
|
The login control on my website is not working and i know it is as a result of the wrong connectionstring. i converted my ASPNETDB.mdf file to ASPNETDB.sql but i dont know wat to do next. can some one help me out please.
|
|
|
|
|
What is the error you are getting?
S Kumar
|
|
|
|