views:

336

answers:

0

Hello, any help on this one will be appreciated..

I use a form for clients to provide them a way to upload their books to a web application.

The clients should be able to upload an image of a book as well.

Just before inserting the book to the database i try to get the image file name and store it a control parameter,in its default value, in the Object datasource_Inserting event. However it keeps using the originally set default value.. WHY FOR HAVENS SAKE??

the code:

//Before the insertion of the Book validate the Image file,bind the filename to the Image parameter

protected void srcInsertNewBook_Inserting(object sender, ObjectDataSourceMethodEventArgs e)
{

    FileUpload upImage = (FileUpload)dtlBook.FindControl("upImage");


    for (int i = 0; i < srcInsertNewBook.InsertParameters.Count; i++)
    {            
        string parname = srcInsertNewBook.InsertParameters[i].Name;

        if (parname == "Image")
        {

          //It should overiwrite the value:"No Image Uploaded" right??IT DOES NOT!
            srcInsertNewBook.InsertParameters[i].DefaultValue = upImage.FileName; 

        }    

    }



    if (upImage.HasFile)
    {
        if (CheckFileType(upImage.FileName))
        {


            if (upImage.PostedFile.ContentLength < 102400)
            {


                //save the file
                String filePath = "~/Book_Images/" + upImage.FileName;
                upImage.SaveAs(MapPath(filePath));


            }
            else
            {
                Alert.Show("The file has to be less than 100 kb!");
                //do not do the insertion!
                e.Cancel = true;
            }

        }
        else
        {

            Alert.Show("No jpg file type!");


            //do not do the insertion!
            e.Cancel = true;



        }    



    }

}

and

    <asp:ObjectDataSource
    id="srcInsertNewBook"
    TypeName="BusinessLogicLayer.Book"
    InsertMethod="InsertNewBook"
    Runat="server" OnInserted="srcInsertNewBook_Inserted" OnInserting="srcInsertNewBook_Inserting">    

   <InsertParameters>

    <asp:ControlParameter  Name="ISBN"  ControlID="dtlBook$txtNewISBN"/>
    <asp:ControlParameter  Name="Publisher_ID"  ControlID="dtlBook$ddlPublishers"/>
    <asp:ControlParameter  Name="Title"  ControlID="dtlBook$txtNewTitle"/>
    <asp:ControlParameter  Name="Category_ID" ControlID="dtlBook$ddlCategories"/>
    <asp:ControlParameter  Name="First_Name"  ControlID="dtlBook$txtNewFirst_Name"/>
    <asp:ControlParameter  Name="Last_Name"  ControlID="dtlBook$txtNewLast_Name"/>
    <%--<asp:ControlParameter  Name="Image"  ControlID="dtlBook$upImage"/>--%>
    <asp:ControlParameter  Name="Description"  ControlID="dtlBook$txtDescription"/>
    <asp:ControlParameter  Name="Price"  ControlID="dtlBook$txtNewPrice"/>
    <asp:ControlParameter  Name="Quantity"  ControlID="dtlBook$txtNewQuantity"/>

    <asp:Parameter Name="Image" DefaultValue="No Image Uploaded" />



    <asp:QueryStringParameter 
      Name="Client"
      QueryStringField="Client" />


    </InsertParameters>

 </asp:ObjectDataSource>

..thanks for any answer.

related questions