Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 4 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB 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 March 15th, 2012, 09:59 AM
Authorized User
 
Join Date: Jan 2011
Posts: 41
Thanks: 0
Thanked 1 Time in 1 Post
Default Something wron with local Server

Hi,

I am testing inputin data in my database. The first I noticed is that most times when I run the website, I get a blank page that say Application_Offline.

Now the site loads fine, but when I try to insert data in the database using the DetailsView control, I keep getting the message: Internet Explorer cannot display te webpage.

Can anyone help me out please?

This is mostly happening with the Image.aspx page. Here is the code-behind for it.

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

public partial class Admin_Images : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //if the page is not a post back, ensure that the GridView is 
        //displaying all images...
        //if (!Page.IsPostBack)
        //{
            int id = Convert.ToInt16(serviceDropDownList1.SelectedItem.Value);

            if (id == 0)
            {
                //! The value of the first item in the dropdown list has been 
                //!set to 0; therefore, once this value is 0, it is certain that
                //!the selected item is not a valid Service. At this point, simply 
                //!display all images.
                GridView1.DataSourceID = "ServiceSqlDataSource";
                GridView1.DataBind();
            }
        //}

        errorLabel.Visible = false;
    }
    protected void serviceDropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        int id = Convert.ToInt16(serviceDropDownList1.SelectedItem.Value);
        if (id == 0)
        {
            //GridView1.DataSourceID = "";
            GridView1.DataSourceID = "ServiceSqlDataSource";
            GridView1.DataBind();
        }
        else
        {
            GridView1.DataSourceID = "SqlDataSource2";
            GridView1.DataBind();
        }
    }
    protected void DetailsView1_ItemInserting(object sender, DetailsViewInsertEventArgs e)
    {
   
       //Get the currently selected service
        int id = Convert.ToInt32(serviceDropDownList1.SelectedItem.Value);

        //if the selected item in the dropdown list is not a valid service
        if (id == 0)
        {
            e.Cancel = true;
            errorLabel.Text = @"You cannot add an image when there is no service 
                                selected. Please select the service from the dropdown 
                                and then try again.";

            errorLabel.Visible = true;
        }
        else
        {
            e.Values["ServiceID"] = id; //Set the ServiceID value in the database
            e.Values["DateAdded"] = DateTime.Now; //Set the DateAdded value in the database



            //Find the FileUpload control in the DetailsView
            FileUpload imageUpload = (FileUpload)DetailsView1.FindControl("FileUpload1");

            string virtualFolder = "~/ServiceImages/"; //set the virtual path of the folder
            string physicalFolder = Server.MapPath(virtualFolder); //set the physical server location
            string filename = Guid.NewGuid().ToString(); //generate a unique name for the file
            string extension = Path.GetExtension(imageUpload.FileName); //get the extension of the file

            //save the file to a physical server location
            imageUpload.SaveAs(Path.Combine(physicalFolder, filename + extension));

            //save the virtual url in the database
            e.Values["ImageUrl"] = string.Format("{0}{1}{2}", virtualFolder, filename, extension);
            

       


        }


        

       
    }
    protected void GridView1_RowDeleted(object sender, GridViewDeletedEventArgs e)
    {
        string deletedUrl = Server.MapPath(Convert.ToString(e.Values["ImageUrl"]));

        File.Delete(deletedUrl);


    }
}
Thank you...
 
Old March 15th, 2012, 10:05 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Since this is not directly related to my book, may I suggest you post this in a general ASP.NET category from this list: http://p2p.wrox.com/asp-net-4-539/

This way, you'll attract more viewers and increase your chance on an answer.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Local vs. Server DB's Ascerbus BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 3 February 7th, 2009 06:04 AM
Local Server Startup Issue.. ankur_icfai SQL Server 2000 2 October 3rd, 2006 04:31 AM
Date Format - Local x Server fskilnik Classic ASP Basics 0 November 2nd, 2005 07:34 AM
Getting the a local copy of the Server DB Sappu SQL Server ASP 2 March 21st, 2005 12:27 PM





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