Reputation: 2180
I have a function that connects to mssql database and and returns a list of stories - those stories are put in Hyperlinks. Here is my code for that:
public void getSocialStories()
{
string user = getSelectedUser();
List<SocialStory> stories = new List<SocialStory>();
stories = functions.getSocialStories(user);
foreach (SocialStory story in stories)
{
HyperLink storyLink = new HyperLink();
storyLink.NavigateUrl = "http://google.com";
storyLink.Text = story.Social_story_name;
ph.Controls.Add(new LiteralControl("<br />"));
ph.Controls.Add(storyLink);
}
}
So far so good, but now I want when a hyperlink is clicked to call a function that asks the database to return the corresponding pictures for that story. All that I need to do is something like calling function(story_id)
. My List<SocialStory>
contains SocialStory objects, which have the story_id
parameter. How can I call a function with the story_id
as a parameter?
Upvotes: 0
Views: 2026
Reputation: 35998
There's no C# at the client's side so you need to make an AJAX call or otherwise query the server somehow.
How to call server side function from client side by passing the argument also? : The Official Microsoft ASP.NET Forums lists a few possible solutions:
They all are based on the same principle: the client sends a second request which invokes a somewhat independent piece of code. They are also considered a lighter alternative to ASMX.
Upvotes: 1
Reputation: 6805
You can use dynamic handler (ashx) to display images inside a tag. So you will need to compose literal control something like this:
<a href="yourStoryLink"><img src="StoryImageHandler.ashx?storyId=yourStoryId" /></a>
Check ASP.NET ASHX Handler to get basic instructions for creating your StoryImageHandler.ashx.
Upvotes: 2