动态创建asp链接按钮来调用c#函数 [英] Dynamically created asp linkbutton to call c# function
本文介绍了动态创建asp链接按钮来调用c#函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码生成一个链接按钮列表:
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);
}
}
我有一个空的asp小组持有人:
And I have a empty asp panelholder:
<asp:PlaceHolder runat="server" ID="ph"></asp:PlaceHolder>
它充满了链接按钮,这是mssql数据库的结果。
我想点击一个链接按钮来调用ac#功能。此函数应该使用social_story_id参数。我怎么能这样做?
我认为其中一种方法是使用Ajax,但我不知道该怎么做。是否有其他方法,如果不是如何使用ajax?
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?
推荐答案
我认为你可以设置LinkButton的post back url将ID传递给相关页面。
查询字符串的内容
http://www.w3schools.com/ASP/coll_querystring.asp [ ^ ]
关于从linkbutton调用函数的东西...
http://www.w3schools.com/aspnet/prop_webcontrol_linkbutton_onclientclick.asp [ ^ ]
希望这些链接能为您提供帮助!
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!
这篇关于动态创建asp链接按钮来调用c#函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文