c# - 在 ASP.NET 中对 LinkBut​​ton 使用 PostBack

标签 c# asp.net user-controls postback

我的 searchresults.aspx 页面中有一个 .ascx 控件:

 <asp:LinkButton id="LinkButton1"
       Text="Click Me" 
       Font-Names="Verdana" 
       Font-Size="14pt" PostBackUrl="~/searchresults.aspx?type=topics"  
       runat="server"/>

但是当我点击它时,它会进行回发,但似乎没有发送 type=topics。有什么建议吗?

最佳答案

试用 HyperLink导航到另一个页面:

<asp:HyperLink NavigateUrl="~/searchresults.aspx?type=topics" />

来自 MSDN:

HyperLink A control that displays a link to another Web page.

关于 LinkButton类(class)页面:

If you want to link to another Web page when the control is clicked, consider using the HyperLink control.

编辑:回复评论

  • 删除 PostBackUrl来自 LinkButton
  • 添加<asp:LinkButton OnClick="OnTopicsTypesEnabled" ... />
  • 在后面的代码中 ( searchresults.aspx.cs )

 protected void OnTopicsTypesEnabled(object sender, EventArgs args)
 {
    // handle this particular case
 }

关于c# - 在 ASP.NET 中对 LinkBut​​ton 使用 PostBack,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7085361/

相关文章:

c# - 以编程方式更改 Excel 中的宏文本

c# - 在 C# 中使用 VB Net 制作的 VB 库

c# - 如何询问任何日期格式是否适合另一个?

c# - 如何从完整的目录文件名中获取文件名?

javascript - 将 Page.IsValid 设置为 False

c# - 如何让 UserControl 派发 HelpRequest 事件

wpf - 将页面或用户控件加载到 XAML 框架元素中有什么区别?

asp.net - jqgrid jsonReader配置

c# - Aspx C# MySQL 连接字符串未使用 web.Config 连接

wpf - 覆盖 XAML 中的资源