Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

My custom validation is not working correctly.

Status
Not open for further replies.

Sanjeet1

Programmer
Sep 4, 2003
26
US
My custom validation is not working correctly. I am trying to use it to display an error message if a file should be updated or not.

When the page loads the filename is stored in viewstate _viewstate.

The user can then select a file from the browse button and make changes. The custom validation needs to check to see if the file names are the same.
If the file names ae the same perform the update if they are not the same the error message should be performed.

Whe I step through the code the filenames ae always the same so the update is always performed.
Here is my code for the custom validation:

public void WrongeFileUpdate_ServerValidate(object source, System.Web.UI.WebControls.ServerValidateEventArgs args)
{
// Display wrong file message if not correct file is selected

if ( _fileId != 0 )
{
//Make sure the file name is from the correct path
_filename = FileHandler.GetShortFileName(_filename);
string newfilename = FileName.Text.ToString();
newfilename = FileHandler.GetShortFileName(newfilename);


if( _filename != newfilename )

{
args.IsValid = false;

}

}
}

This is where my update is called:

private void Update_Click(object sender, System.EventArgs e)
{

if (!Page.IsValid)
return;

OnlineCaseFileInfo file = new OnlineCaseFileInfo();
OnlineCaseFileController controller = new OnlineCaseFileController();



file.CaseId = _caseId;
file.FileDescription = FileDescription.Text;
file.SortOrder = int.Parse( txtsort.Text );


// New File Browse button visible for editing a file
HttpPostedFile pFile = NewFileName.PostedFile;
byte[] fileData = new byte[pFile.ContentLength];
pFile.InputStream.Read( fileData, 0, pFile.ContentLength );
file.FileId = FileHandler.SaveFile( _caseId, fileData, pFile.FileName );
file.FileName = FileHandler.GetShortFileName( pFile.FileName );

string newfilename = file.FileName.ToString();



if ( _fileId == 0 )



{
// Add file if file id is 0

controller.Add( file );
}

else // update file if file exists



{

file.FileId = _fileId;
controller.Update( file );


}

controller = null;

//redirect
Cancel_Click( null, null );
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top