Naresh
Naresh

Reputation: 657

How to use dynamic hyperlink as a Button to use on-click event.ASP.NET(C#)

I'm using a hyperlink like this to delete a directory when it is clicked.

 Response.Write("<a href= delete.aspx?path=" + 
     directory.FullName + ">DELETE </a>");
    }

But for this I'm being redirected to delete.aspx.Can I do it like button where path will be passed as parameters for the onclick function.

Upvotes: 0

Views: 1363

Answers (4)

Nuno Agapito
Nuno Agapito

Reputation: 230

<asp:LinkButton /> with onclick event and CommandName and CommandArguments properties?

Upvotes: 1

vikas mehta
vikas mehta

Reputation: 458

are you looking for,

string page = "delete.aspx";

Response.Write("<a href= "+page+"?path=" +directory.FullName + ">DELETE </a>"); 

you can decide the value for page string

Upvotes: 0

Bibhu
Bibhu

Reputation: 4081

In the "Delete.aspx" page you must be fetching the query string value and in the page load, you must be having the code to delete the directory.

Now if you don't want to do this in the "Delete.aspx" page, add a button to the current page, then just move the code present in page load of "Delete.aspx" to the button click event of the current page(in which you have the hyperlink) and use the directory value(global value) in the button_click function.

Upvotes: 1

Peyman
Peyman

Reputation: 3138

You can create the ASHX (Handler Page) instead of ASP.NET page. And also see this document.

Upvotes: 0

Related Questions