Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > BOOK: Beginning ASP.NET 4 : in C# and VB
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old March 15th, 2012, 09:59 AM
Authorized User
Points: 194, Level: 3
Points: 194, Level: 3 Points: 194, Level: 3 Points: 194, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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...
Reply With Quote
  #2 (permalink)  
Old March 15th, 2012, 10:05 AM
Imar's Avatar
Wrox Author
Points: 71,632, Level: 100
Points: 71,632, Level: 100 Points: 71,632, Level: 100 Points: 71,632, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,013
Thanks: 79
Thanked 1,576 Times in 1,553 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!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 05: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 06:34 AM
Getting the a local copy of the Server DB Sappu SQL Server ASP 2 March 21st, 2005 11:27 AM



All times are GMT -4. The time now is 12:34 PM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.