开发者

Using a PostBack on a LinkButton in ASP.NET

I have an .ascx control in my searchresults.aspx page:

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

But when I click on it, it does the postback but the type=topics doesn't appear to be sent. Any suggestions?


Try out HyperLink to navigate to an other page:

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

From MSDN:

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

On LinkButton class page:

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

EDIT: Answer to comments

  • Remove PostBackUrl from LinkButton
  • Add <asp:LinkButton OnClick="OnTopicsTypesEnabled" ... />
  • In code behind (searchresults.aspx.cs)

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


I believe your code will perform an POST, whereas you need a GET to transfer your variables through QueryString.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜