1
public string GetRandomImage(string StrDirectory, string StrFileName)
{
    Response.Write("Test: GetRandomImage True");
    string GetRandomImage;
    int IntFileCount = Directory.GetFiles(Server.MapPath(StrDirectory), "*.*", SearchOption.TopDirectoryOnly).Length;
    Random Random1 = new Random();
    IntFileCount = IntFileCount + 1;
    GetRandomImage = StrDirectory + StrFileName + Random1.Next(1, IntFileCount) + ".png";
    Response.Write(GetRandomImage);
    return GetRandomImage;
}

this code is in my codebehind file (default.aspx.cs). i want to call it from my default.aspx file. I tried to call with

<%# GetRandomImage("images/random/","random_") %>

but i have get error. How can I do this? Thank you for all helper(s) and your help(s).

1
  • What is the error you're getting? Commented Sep 30, 2009 at 8:19

2 Answers 2

2

You can call it with the fully qualified namespace if its a static method or with a this if its a page method. Use an equal sign instead of hash

<%= this.GetRandomImage("images/random/","random_") %>
Sign up to request clarification or add additional context in comments.

2 Comments

I could not understand. What you told me.
First, i want to thank you for your help. I have used your suggestion. I have not get error but it has not return string value. So i have solved my issue in codebehind's Page_Load event with using asp.net's imageURL attribute of image control. Thank you again.
0

# requires a call to DataBind() on the control.

protected string GetRandomImage(string StrDirectory, string StrFileName)
{
    Response.Write("Test: GetRandomImage True");
    string GetRandomImage;
    int IntFileCount = Directory.GetFiles(Server.MapPath(StrDirectory), "*.*", SearchOption.TopDirectoryOnly).Length;
    Random Random1 = new Random();
    IntFileCount = IntFileCount + 1;
    GetRandomImage = StrDirectory + StrFileName + Random1.Next(1, IntFileCount) + ".png";
    Response.Write(GetRandomImage);
    return GetRandomImage;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.