cdub
cdub

Reputation: 25701

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 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?

Upvotes: 1

Views: 10778

Answers (2)

sll
sll

Reputation: 62504

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
 }

Upvotes: 3

James Johnson
James Johnson

Reputation: 46047

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

Upvotes: 1

Related Questions