B. Nir
B. Nir

Reputation: 119

How to refresh a web page in asp.net

In my code i added dynamically some text-boxes and labels.
Then by dropdownlist event i want to refresh the page in a way that all the added text-boxes and labels will remove from aspx

how can it be done?

Upvotes: 0

Views: 120

Answers (2)

Maverick
Maverick

Reputation: 801

  1. Add AutoPostBack="True" for the DropDownList

  2. Add an event to DropDownList for SelectedIndexChange
    OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"

  3. In the Code-Behind file :

    private void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (DropDownList1.SelectedIndex == 0)
        {
            Label1.Visible = false;
        }
        else
        {
            Label2.Visible = false;
        }
    }
    

Upvotes: 0

htxryan
htxryan

Reputation: 2961

I assume you're using C#.

You can redirect to the current page by doing this from your code-behind:

Response.Redirect(HttpContext.Current.Request.Url.AbsoluteUri);

Upvotes: 1

Related Questions