Help .. Button does not function properly.

C

Chuck

I hope someone can help me out. I am trying to create a simple page
with a drop down list that gives the user the ability to select which
url they would like to run. The url does call a javascript function
"openWin" that opens the browser to a specific size.

The problem is that everytime I select a value in the drop down list I
have to click the button twice to get the right url to open. The first
time always opens the wrong url.

Here's my code..
-------------------------------------------------------------------
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Select Case DropDownList1.SelectedValue
Case "0"
Button1.Attributes.Add("language", "javascript")
Button1.Attributes.Add("onClick",
"openWin('http://www.microsoft.com');return true;")
Case "1"
Button1.Attributes.Add("language", "javascript")
Button1.Attributes.Add("onClick",
"openWin('http://www.yahoo.com');return true;")
End Select
End Sub

---------------------------------------------------------------

<form id="Form1" method="post" runat="server">
<asp:dropdownlist id="DropDownList1" style="Z-INDEX: 101; LEFT:
160px; POSITION: absolute; TOP: 40px"
runat="server" Width="208px">
<asp:ListItem Value="0"
Selected="True">microsoft.com</asp:ListItem>
<asp:ListItem Value="1">yahoo.com</asp:ListItem>
</asp:dropdownlist>
<asp:Button id="Button1" runat="server" Text="Button"
CausesValidation="False"></asp:Button>
</form>

-------------------------------------------------------------------
 
D

David Lloyd

Chuck:

You may want to set the EnableViewState property of the dropdownlist to
false.

--
David Lloyd
MCSD .NET
http://LemingtonConsulting.com

This response is supplied "as is" without any representations or warranties.


I hope someone can help me out. I am trying to create a simple page
with a drop down list that gives the user the ability to select which
url they would like to run. The url does call a javascript function
"openWin" that opens the browser to a specific size.

The problem is that everytime I select a value in the drop down list I
have to click the button twice to get the right url to open. The first
time always opens the wrong url.

Here's my code..
-------------------------------------------------------------------
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Select Case DropDownList1.SelectedValue
Case "0"
Button1.Attributes.Add("language", "javascript")
Button1.Attributes.Add("onClick",
"openWin('http://www.microsoft.com');return true;")
Case "1"
Button1.Attributes.Add("language", "javascript")
Button1.Attributes.Add("onClick",
"openWin('http://www.yahoo.com');return true;")
End Select
End Sub

---------------------------------------------------------------

<form id="Form1" method="post" runat="server">
<asp:dropdownlist id="DropDownList1" style="Z-INDEX: 101; LEFT:
160px; POSITION: absolute; TOP: 40px"
runat="server" Width="208px">
<asp:ListItem Value="0"
Selected="True">microsoft.com</asp:ListItem>
<asp:ListItem Value="1">yahoo.com</asp:ListItem>
</asp:dropdownlist>
<asp:Button id="Button1" runat="server" Text="Button"
CausesValidation="False"></asp:Button>
</form>

-------------------------------------------------------------------
 
A

Artur-ek

Chuck said:
I hope someone can help me out. I am trying to create a simple page
with a drop down list that gives the user the ability to select which
url they would like to run. The url does call a javascript function
"openWin" that opens the browser to a specific size.

The problem is that everytime I select a value in the drop down list I
have to click the button twice to get the right url to open. The first
time always opens the wrong url.

Here's my code..
-------------------------------------------------------------------
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Select Case DropDownList1.SelectedValue
Case "0"
Button1.Attributes.Add("language", "javascript")
Button1.Attributes.Add("onClick",
"openWin('http://www.microsoft.com');return true;")
Case "1"
Button1.Attributes.Add("language", "javascript")
Button1.Attributes.Add("onClick",
"openWin('http://www.yahoo.com');return true;")
End Select
End Sub

---------------------------------------------------------------

It's quite obvious that it needs two clicks.
First click sets the button's attribute onClick="openWin('htt..')".
Second click activates this event.
 

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

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top