Question: I want to delete a `directory` when its clicked on a `hyperlink`.I tried like the below.But my page redirecting to `default(start) page` and the `directory` is not deleting.

```
protected void Page_Load(object sender, EventArgs e)
{
    Execute(s,Content,k,j);
}

private void Execute(string path,string cont,string sym,string space )
{
    foreach (var directory in new DirectoryInfo(path).GetDirectories())
    {
        string f = directory.FullName;  
        f = Server.UrlPathEncode(f);

        Response.Write("<a href =''" + "onclick='Delete(" + f + ")'> DELETE </a>");

        Execute(directory.FullName,cont1,sym1,space1);
    }
}

private void Delete(string path)
{
    DirectoryInfo DirDel = new DirectoryInfo(path);
    DirDel.Delete();
}

```

Can you tell me the problem in this code?

Answer: 
The **general problem** is that you create client-side URLs, but method to call is server-side. So you need to create server-side URLs, and handle postback click:

```
string path = @"d:\Temp";

protected override void OnInit(EventArgs e)
{
    string dir = this.Request["dir"];
    if (String.IsNullOrEmpty(dir)) // write links
    {
        foreach (var di in new DirectoryInfo(path).EnumerateDirectories())
        {
            var link = new HyperLink()
            {
                Text = di.Name,
                NavigateUrl = String.Format("?dir={0}", HttpUtility.UrlEncode(di.Name))
            };
            this.Controls.Add(link);
        }
    }
    else // process link click
    {
        dir = HttpUtility.UrlDecode(dir);
        path = Path.Combine(path, dir);
        Directory.Delete(path);

        Response.Redirect("~/Default.aspx"); // page's name to refresh content
    }
}

```
You should use a LinkButton to get the same look as the , but you need your code to be execute on server side as the PostBack for your LinkButton.

The code you have here will make a call to a client-side script.