locked
Change url after postback RRS feed

  • Question

  • User944339287 posted
    hi guys.. i have a dropdownlist at index.aspx and set to autopostback = true

    how can i amend the url to index.aspx?action=changed while SelectedIndexChanged is triggered?
    Monday, May 11, 2020 11:06 AM

All replies

  • User475983607 posted

    Your requirement is not totally clear but you can redirect in the event.

        <asp:DropDownList ID="DropDownList1" runat="server" 
            autopostback="true" 
            OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
            <asp:ListItem Text="Select" Value="0"></asp:ListItem>
            <asp:ListItem Text="Option" Value="1"></asp:ListItem>
        </asp:DropDownList>
        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            Response.Redirect("~/index.aspx?action=changed");
        }

    Monday, May 11, 2020 11:18 AM
  • User1535942433 posted

    Hi kengkit,

    Accroding to your description,as far as I think,you could add parameters in the Redirect.

    Since you don't post your codes to us,I create a demo.

    If you have other problems,I suggest you could tell us more details of you requirment and post your full codes to us.It will help us to solve your problems.

    More details,you could refer to below codes:

    <div>
                <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
                    <asp:ListItem Value="1" Text="AA"></asp:ListItem>
                    <asp:ListItem Value="2" Text="BB"></asp:ListItem>
                </asp:DropDownList>
            </div>

    Code-Behind:

     Protected Sub DropDownList1_SelectedIndexChanged(sender As Object, e As EventArgs)
            Response.Redirect(Request.Url.AbsolutePath + "?action=changed")
    
        End Sub

    Result:

    Best regards,

    Yijing Sun

    Tuesday, May 12, 2020 1:52 AM