problem with redirecting when clicking on a button


E

Eric

Hi,

I defined a button dynamically. The button must redirect to the main menu.
First the dropdownlist1 is shown. When the user chooses a value, because
AutoPostBack=true, the procedure DropDownList1_SelectedIndexChanged is
started, creating the button dynamically.

My problem is that the button doesn't redirect to the mainmenu.aspx page,
but sends the user to the beginning of this page, showing the dropdownlist
with the chosen value but without showing the button.

Can anybody tell me why and how to fix it?
Thanks
Eric


Here the code:

aspx file:
--------
<asp:Button ID="Button1" runat="server" />
<asp:DropDownList ID="DropDownList1" AutoPostBack="true" runat="server">
</asp:DropDownList>

code-behind:
-------------
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
'here the dropdownlist1 is feeded with data.
end sub

Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged

Dim bt As New Button
form1.Controls.Add(bt)
AddHandler bt.Click, AddressOf bt_Click
end sub

Protected Sub bt_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Response.Redirect("mainmenu.aspx", False)
End Sub
 
Ad

Advertisements

E

Eric

Thanks for replying.

I omitted that in the procedure Protected Sub
DropDownList1_SelectedIndexChanged, before the creation of the button, other
controls (dropdownlists) are also created.

The problem with your solution (which works) is now that the button is
created before all those controls instead of after. Not a dramatical
situation, but not logical, because the user must first go down till the
last control and then back at the top of the page for clicking on the
button.

Thanks
Eric



The problem i have when doing your way is that the
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top