[英]OnServerClick on anchor tag is not firing
I have 3 tabs, On which I want to show the respective data. 我有3个标签,我想在这些标签上显示相应的数据。 I have given a attribute as
onserverclick
to the anchor tag inside <li>
. 我给
<li>
内的锚标记赋予了属性onserverclick
。 but the problem is that it is not firing. 但问题在于它没有开火。
Also When I tried putting a breakpoint it was not working. 另外,当我尝试放置一个断点时,它不起作用。 Here is my piece of html code:-
这是我的html代码:-
<ul class='tabs1'>
<li><a href='#tab1' id="allNews" runat="server" onserverclick="allNews_ServerClick">All News</a></li>
<li><a href='#tab2' id="forNgo" runat="server" onserverclick="forNgo_ServerClick">For NGO</a></li>
<li><a href='#tab3' id="fromNgo" runat="server" onserverclick="fromNgo_ServerClick">From NGO</a></li>
</ul>
Please suggest what might be the issue which is preventing to work. 请提出可能导致无法正常工作的问题。
UPDATE UPDATE
Server code:- 服务器代码:
protected void fromNgo_ServerClick(object sender, EventArgs e)
{
using (SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["DefaultCSRConnection"].ConnectionString))
{
string query = "SSELECT dbo.tbl_post.title, dbo.tbl_post.description, dbo.tbl_post.active, dbo.tbl_post.dateforPost, dbo.tbl_ngoname.ngo_name, dbo.tbl_User.usertype FROM dbo.tbl_post INNER JOIN dbo.tbl_User ON dbo.tbl_post.UserId = dbo.tbl_User.Id INNER JOIN dbo.tbl_ngoname ON dbo.tbl_post.NgoId = dbo.tbl_ngoname.Id AND dbo.tbl_User.NgoId = dbo.tbl_ngoname.Id WHERE (dbo.tbl_User.usertype=2)";
SqlDataAdapter sda = new SqlDataAdapter(query, conn);
DataTable dt = new DataTable();
sda.Fill(dt);
lstNews.DataSource = dt;
lstNews.DataBind();
}
}
protected void Tab1Function()
{
using (SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["DefaultCSRConnection"].ConnectionString))
{
string query = "SELECT dbo.tbl_post.title, dbo.tbl_post.description, dbo.tbl_post.active, dbo.tbl_post.dateforPost, dbo.tbl_ngoname.ngo_name, dbo.tbl_User.usertype FROM dbo.tbl_post INNER JOIN dbo.tbl_User ON dbo.tbl_post.UserId = dbo.tbl_User.Id INNER JOIN dbo.tbl_ngoname ON dbo.tbl_post.NgoId = dbo.tbl_ngoname.Id AND dbo.tbl_User.NgoId = dbo.tbl_ngoname.Id WHERE (dbo.tbl_User.usertype=2)";
SqlDataAdapter sda = new SqlDataAdapter(query, conn);
DataTable dt = new DataTable();
sda.Fill(dt);
lstNews.DataSource = dt;
lstNews.DataBind();
}
}
And then, use this in your PageLoad 然后,在您的PageLoad中使用它
If (!IsPostBack)
{
Tab1Function();
}
Something like that. 这样的事情。
EDIT: I think your tabs are not working. 编辑:我认为您的选项卡不起作用。 So lets direct you to the TabContainer then.
因此,然后将您定向到TabContainer。
<ajaxToolkit:TabContainer ID="Tab_Container" runat="server" ActiveTabIndex="0" CssClass="CustomTabStyle" EnableTheming="False" ScrollBars="Both" Style="vertical-align: top" Width="900px">
<ajaxToolkit:TabPanel ID="TabPanel_1" runat="server" HeaderText="TabPanel1" ScrollBars="Both">
<HeaderTemplate> All News </HeaderTemplate>
<ContentTemplate>
//Your Table/Datagrid containing your data here.. Whatever you are binding your data to.
<table><tr><td></td></tr></table>
</ContentTemplate>
</ajaxToolkit:TabPanel>
<ajaxToolkit:TabPanel ID="TabPanel_2" runat="server" HeaderText="TabPanel3">
<HeaderTemplate>
For NGO
</HeaderTemplate>
<ContentTemplate>
<table><tr><td></td></tr></table>
</ContentTemplate></ajaxToolkit:TabPanel></ajaxToolkit:TabContainer>
I hope that makes sense. 我希望这是有道理的。
You need to create the Click event for Anchor tag in page load as below 您需要在页面加载中为Anchor标签创建Click事件,如下所示
private void Page_Load(object sender, System.EventArgs e)
{
HtmlAnchor HA = new HtmlAnchor();
HA.ServerClick += new EventHandler(linkclickeve1);
HtmlAnchor HA2 = new HtmlAnchor();
HA2.ServerClick += new EventHandler(linkclickeve2);
}
protected void linkclickeve1(object sender, System.EventArgs e)
{
}
protected void linkclickeve2(object sender, System.EventArgs e)
{
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.