Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

random image generation in asp.net

Posted on 2010-01-05
10
Medium Priority
?
522 Views
Last Modified: 2012-05-08
Error      1      Validation (Internet Explorer 6): Content is not supported outside 'script' or 'asp:content' regions.      D:\RanImg\random.aspx      7      2      D:\RanImg\
Error      2      Element 'Image' is not a known element. This can occur if there is a compilation error in the Web site.      D:\RanImg\random.aspx      14      14      D:\RanImg\
Error      3      File '~/web.master' was not found.      D:\RanImg\random.aspx      2      40      D:\RanImg\
Error      4      The file '/RanImg/web.master' does not exist.      D:\RanImg\random.aspx      2      

<%--<%@ Page Language="C#" AutoEventWireup="true" CodeFile="random.aspx.cs" Inherits="Default2" %>--%>
<%@ Page Language="C#" MasterPageFile="~/web.master" AutoEventWireup="true" CodeFile="random.aspx.cs" Inherits="random" Title="Untitled Page" %>
 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Image ID="imgImage" runat="server" Style="z-index: 100; left: 138px; position: absolute;
            top: 187px" Width="86px" />
    
    </div>
    </form>
</body>
</html>

Open in new window

0
Comment
Question by:sunda2010
  • 5
  • 4
10 Comments
 
LVL 15

Expert Comment

by:rajeeshmca
ID: 26187974
HI sunda2010,

The problem is the page is inside a master page... see

<%@ Page Language="C#" MasterPageFile="~/web.master" AutoEventWireup="true" CodeFile="random.aspx.cs" Inherits="random" Title="Untitled Page" %>

When a page is inside a master page, it should be within a <asp:contentPlaceHolder />

U cannot have a new form within a master page like

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Image ID="imgImage" runat="server" Style="z-index: 100; left: 138px; position: absolute;
            top: 187px" Width="86px" />
   
    </div>
    </form>
</body>
</html>

It shoul be as like

<%@ Page Language="C#" MasterPageFile="~/web.master" AutoEventWireup="true" CodeFile="random.aspx.cs" Inherits="random" Title="Untitled Page" %>

<asp:PlaceHolder id="Content" contentPlaceHolderId="The id in the Master Page">
    <div>
        <asp:Image ID="imgImage" runat="server" Style="z-index: 100; left: 138px; position: absolute;
            top: 187px" Width="86px" />
   
    </div>

</asp:PlaceHolder>



0
 

Author Comment

by:sunda2010
ID: 26188117
I try what u said.......
That showing following Error......

Error      1      File '~/web.master' was not found.      D:\RanImg\random.aspx      3      41      D:\RanImg\
Error      2      Validation (Internet Explorer 6): Content is not supported outside 'script' or 'asp:content' regions.      D:\RanImg\random.aspx      8      2      D:\RanImg\
Error      3      Element 'PlaceHolder' is not a known element. This can occur if there is a compilation error in the Web site.      D:\RanImg\random.aspx      14      10      D:\RanImg\
Error      4      Element 'Image' is not a known element. This can occur if there is a compilation error in the Web site.      D:\RanImg\random.aspx      16      13      D:\RanImg\
Error      5      The file '/RanImg/web.master' does not exist.      D:\RanImg\random.aspx      3      


pls send the solution for this
0
 
LVL 15

Accepted Solution

by:
rajeeshmca earned 500 total points
ID: 26188181
Is there a master page in your application? If no then change the

Page attribiute to

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="random.aspx.cs" Inherits="Default2" %>

and just add the below to ur page

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
   <title>Untitled Page</title>
</head>
<body>
   <form id="form1" runat="server">
   <div>
       <asp:Image ID="imgImage" runat="server" Style="z-index: 100; left: 138px; position: absolute;
           top: 187px" Width="86px" />
   
   </div>
   </form>
</body>
</html>

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:sunda2010
ID: 26188198
The following Errors are occuring.........

Error      1      'ASP.random_aspx.GetTypeHashCode()': no suitable method found to override      c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\ranimg\9fa138ff\9216c1da\App_Web__hugwcfb.2.cs      
Error      2      'ASP.random_aspx.ProcessRequest(System.Web.HttpContext)': no suitable method found to override      c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\ranimg\9fa138ff\9216c1da\App_Web__hugwcfb.2.cs      
Error      3      'ASP.random_aspx' does not implement interface member 'System.Web.IHttpHandler.IsReusable'      c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\ranimg\9fa138ff\9216c1da\App_Web__hugwcfb.2.cs      

send me clearly....
0
 
LVL 15

Assisted Solution

by:rajeeshmca
rajeeshmca earned 500 total points
ID: 26188229
HI sunda2010,

These are all the errors in the code behind page (cs Page). So of possible post your aspx and cs pages. I will try to sort it out.

which framework are u using?
0
 
LVL 12

Expert Comment

by:madhevan_pillai
ID: 26188482
Hi,

Move this

  c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\ranimg\9fa138ff\9216c1da\App_Web__hugwcfb.2.cs  

to a temp folder and compile.
0
 

Author Comment

by:sunda2010
ID: 26189041
random.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //Show the path to the folder which contains the files you wish to randomly select from
    string directory = "/RanImg/images";//"/common/images/random/";
 
    //Create a string array to contain the images
    string[] images = Directory.GetFiles(HttpContext.Current.Server.MapPath(directory));
 
    //Check to see if any images exist and if so display a random one
    if (images.Length > 0)
    {
        int rnd = new Random().Next(0, images.Length);
        imgRandom.ImageUrl = directory + Path.GetFileName(images[rnd]);
   

  }

    }  
}




random.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="random.aspx.cs" Inherits="random" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
   <title>Untitled Page</title>
</head>
<body>
   <form id="form1" runat="server">
   <div>
       <asp:Image ID="imgImage" runat="server" Style="z-index: 100; left: 138px; position: absolute;
           top: 187px" Width="86px" />
   
   </div>
   </form>
</body>
</html>

This is my code....
   
0
 
LVL 15

Assisted Solution

by:rajeeshmca
rajeeshmca earned 500 total points
ID: 26189353
Hi sunda2010,

The code works good for me....

do one thing

Create a new aspx page, delete everything except page directive and add the following

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:Image ID="imgImage" runat="server" Style="z-index: 100; left: 138px; position: absolute;
                top: 187px" Width="86px"  />
        </div>
    </form>
</body>
</html>

In the code behind

add the following

protected void Page_Load(object sender, EventArgs e)
    {
        //Show the path to the folder which contains the files you wish to randomly select from
        string directory = "/images";//"/common/images/random/";

        //Create a string array to contain the images
        string[] images = Directory.GetFiles(HttpContext.Current.Server.MapPath("images"));

        //Check to see if any images exist and if so display a random one
        if (images.Length > 0)
        {
            int rnd = new Random().Next(0, images.Length);
            imgImage.ImageUrl = "~" + directory + "/" + Path.GetFileName(images[rnd]);


        }
    }

also add the using directive

using System.IO;

also change the url ie.  imgImage.ImageUrl  according to your requirement
0
 

Author Closing Comment

by:sunda2010
ID: 31673359
Your Reply was well..
0
 

Author Comment

by:sunda2010
ID: 26207189
Error      1      'ASP.random_aspx.GetTypeHashCode()': no suitable method found to override      c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\ranimg\9fa138ff\9216c1da\App_Web_g5v5lae2.0.cs      
Error      2      'ASP.random_aspx.ProcessRequest(System.Web.HttpContext)': no suitable method found to override      c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\ranimg\9fa138ff\9216c1da\App_Web_g5v5lae2.0.cs      
Error      3      'ASP.random_aspx' does not implement interface member 'System.Web.IHttpHandler.IsReusable'      c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\ranimg\9fa138ff\9216c1da\App_Web_g5v5lae2.0.cs      


The Above Error is Occuring..
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The purpose of this article is to demonstrate how we can use conditional statements using Python.
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question