锚标记上的 OnServerClick 未触发
OnServerClick on anchor tag is not firing
我有 3 个选项卡,我想在其中显示相应的数据。我已将属性 onserverclick
赋予 <li>
内的锚标记。但问题是它没有开火。
此外,当我尝试放置断点时,它不起作用。这是我的一段 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>
请提出阻止工作的可能问题。
更新
服务器代码:-
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();
}
}
然后,在您的 PageLoad
中使用它
If (!IsPostBack)
{
Tab1Function();
}
类似的东西。
编辑:我认为您的选项卡不起作用。那么让我们引导您到 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>
我希望这是有道理的。
您需要为页面加载中的锚标记创建点击事件,如下所示
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)
{
}
我有 3 个选项卡,我想在其中显示相应的数据。我已将属性 onserverclick
赋予 <li>
内的锚标记。但问题是它没有开火。
此外,当我尝试放置断点时,它不起作用。这是我的一段 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>
请提出阻止工作的可能问题。
更新
服务器代码:-
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();
}
}
然后,在您的 PageLoad
中使用它 If (!IsPostBack)
{
Tab1Function();
}
类似的东西。
编辑:我认为您的选项卡不起作用。那么让我们引导您到 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>
我希望这是有道理的。
您需要为页面加载中的锚标记创建点击事件,如下所示
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)
{
}