Click here to Skip to main content
11,578,524 members (58,992 online)
Rate this: bad
good
Please Sign up or sign in to vote.
I have the following code which generates a list of linkbuttons:

public void getSocialStories()
    {
        string user = getSelectedUser();
        List<SocialStory> stories = new List<SocialStory>();
        stories = functions.getSocialStories(user);
 
        foreach (SocialStory story in stories)
        {
            LinkButton lb = new LinkButton();
            lb.Text = story.Social_story_name;
            ph.Controls.Add(new LiteralControl("<br />"));
            ph.Controls.Add(lb);
        }
    }

And I have a empty asp panelholder:

<asp:PlaceHolder runat="server" ID="ph"></asp:PlaceHolder>

It gets filled with the linkbuttons, which are a result from a mssql database.

I want when a linkbutton is clicked to call a c# function. This function should take a parameter the social_story_id. How can I do that ?

I think one of the ways is using Ajax, but I don't know how to do it. Are there other ways and if not how to do it with ajax?
Posted 17-Dec-12 3:04am
Comments
RobBranaghan at 17-Dec-12 9:24am
   
Can you set the tag of the literal control?
Member 9635907 at 17-Dec-12 9:28am
   
what do you mean by that ? I am still learning and that's why I am asking such questions.
RobBranaghan at 17-Dec-12 9:39am
   
Sorry miss reading your post.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I think that you could set the post back url of the LinkButton to pass the ID to the relevant page.

Something about query strings
http://www.w3schools.com/ASP/coll_querystring.asp[^]

Something about calling functions from linkbutton...

http://www.w3schools.com/aspnet/prop_webcontrol_linkbutton_onclientclick.asp[^]

Hope these links help you!
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web03 | 2.8.150603.1 | Last Updated 17 Dec 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100