5

I would like to use substitution feature of donut caching.

public static string GetTime(HttpContext context)
{
    return DateTime.Now.ToString("T");
}

...

The cached time is: <%= DateTime.Now.ToString("T") %>
<hr />
The substitution time is:
<% Response.WriteSubstitution(GetTime); %>

...But I would like to pass additional parameter to callback function beside HttpContext.
so the question is:
How to pass additional argument to GetTime callback?
for instance, something like this:

public static string GetTime(HttpContext context, int newArgument)
{
    // i'd like to get sth from DB by newArgument
    // return data depending on the db values

    // ... this example is too simple for my usage
    if (newArgument == 1)
        return "";
    else
        return DateTime.Now.ToString("T");
}
zzare
  • 98
  • 2
  • 8
  • 1
    So the answer i was looking for is: IT CAN NOT BE DONE :) Problem in my situation is that i'm dinamically inserting multiple(>=0) POLL controls on the page and I want to render each control based on arguments (UserID and PollID. if user has already voted, there must be results of the poll instead of voting form, for each control). So I can not define different functions. In the end i've used ajax call to retrieve results for each of the voted poll on $(document).ready event. But I was hoping for a nicer solution... Thanks to all for your help – zzare Jun 17 '10 at 11:12

2 Answers2

2

Otherwise, if your problem is that you want to have different outputs based on different arguments because you're using the output substitution in different places on your website, I'm afraid the only way is to either define different functions or to only use the substitution methods as a stub for the actual method with arguments.

ErikHeemskerk
  • 1,623
  • 14
  • 30
1

Well, you can store any argument you need in the Session. In method GetTime, these arguments can be accessed through the HttpContext.

S P
  • 4,615
  • 2
  • 18
  • 31
  • The `Session` is not available when using the `Substitution` control. It is listed in the `Context` instance but is always null when in a static call-back method as it is never initialized and loaded when called via the Substitution feature. – Jon Adams Oct 19 '11 at 17:37