'C# call method once and append to existing values before before binding to gridview

my question is how can i call the method from dal layer to generate sas token only once and save the value in the code behind file and no matter how many different pages it hits after that when it returns back in the end append the sastoken to the imageid. I tried storing it a session that came back null after all the pages.

Example

DalLayer.cs

  public string imagereference(quizid, locationid, string pagevalue)
    {
     if(pagevalue == "quiz")
    {
      i generate a imageurl; --gets called twice
    }
    else
    {
    i generate url of the image for summary -- gets called 20 times.
    }
    }
    private static string getsastoken(accountname, accountkey, credential, blobcontainer)
    {
    --there is more that goes here im getting the sastoken back thats not the issue so did not post more code.
    sastoken = blobsasbuilder.ToSasQueryParameters(credentail);
    return sastoken;
    }

QuizSummary.aspx

<div id = "divQuiz">
<image id= "quizQuestion" runat= server class="something421" />
</div>

QuizSummary.aspx.cs

i call the method from dal layer in code behind where the image gets binded 20 times and each time the sastoken method and image ref method is called that is the bad practice i want to avoid. on the same page i want to call getsastoken method only once load these values somehow and keep it till the end of session on codebehind and append it to the image path coming into the codebehind.

any help would be appreciated.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source