Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 20th, 2005, 12:45 PM
Authorized User
 
Join Date: Aug 2003
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default Error msage not getting disayed

OK What I am trying to do is display the message in my custom validator that a file was not selected only if the user select an update button with out selecting the file.

This is what's happening:

1. Curently the update link can add a new file or modify an existing file. view state is used to see if a file already exists or not:

private int _fileId
          {
               get
               {
                    if ( ViewState[ "FileId" ] != null )
                         return Convert.ToInt32( ViewState[ "FileId" ] );
                    else
                         return 0;
               }
               set { ViewState[ "FileId"] = value; }
          }


2. When the user clicks the file update button this is what gets processed.:

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

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

     file.CaseId = _caseId;
     file.FileDescription = FileDescription.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 );

     if (!Page.IsValid) // Now this code will call the validate function
               return;




                    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;


3. This function gets called:


          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, only file name should be compared
                    _filename = FileHandler.GetShortFileName(_filename); //FileHandler GetShortFile name retreives only the file name
                    // New File Browse button visible for editing a file
                    OnlineCaseFileInfo file = new OnlineCaseFileInfo();
                    OnlineCaseFileController controller = new OnlineCaseFileController();



                    file.CaseId = _caseId;
                    file.FileDescription = FileDescription.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 = FileHandler.GetShortFileName( pFile.FileName );
                    newfilename = FileHandler.GetShortFileName(newfilename);

                    if( _filename != newfilename )

                    {

                         WrongeFileUpdate.Text = "Wrong File Being Updated";
                         args.IsValid = false;
                    }

               }

               if ( _fileId == 0)
               {
                    if (this.NewFileName.Value == "")
                    {
                    WrongeFileUpdate.Text = "No File Selected. Please select a file."; // So the code does reach here when I step through it.
                                                                args.IsValid = false;
                    }
               }

4. However after it finishes executing this function. It displays this error message:

A critical error has occurred.
Could not find a part of the path "C:\DNNmyAANS\Portals\0\onlinecase\5\".


Sanjeet
__________________
Sanjeet





Similar Threads
Thread Thread Starter Forum Replies Last Post
Parse error: syntax error, unexpected T_ELSE in /h vipin k varghese BOOK: XSLT Programmer's Reference, 2nd Edition 4 September 29th, 2011 01:19 AM
Insert Query Error & Run-Time Error 3022 DavidWE Access 1 July 31st, 2008 11:17 AM
Ch 4: Parse error: syntax error, unexpected T_SL hanizar77 BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 0 June 23rd, 2008 09:17 PM
Parse error: syntax error, unexpected T_STRING ginost7 Beginning PHP 1 November 9th, 2007 02:51 AM
Phile Page error, visual studio error reps BOOK: ASP.NET Website Programming Problem-Design-Solution 0 September 27th, 2003 10:11 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.