Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > autoselect all items in <SELECT> control is undone when form submits

Reply
Thread Tools

autoselect all items in <SELECT> control is undone when form submits

 
 
Mad Scientist Jr
Guest
Posts: n/a
 
      03-05-2004
I'm stuck trying to work with a HTML <SELECT> control and javascript
(similar to DualList but that control doesn't offer enough options to
totally control the text on the buttons and control, also I don't have
c# on this machine to try and modify it).. anyway...

I'm trying to get javascipt to select all items in a <SELECT> control
and submit the form to an asp.net page. For some reason when the link
is clicked, you can see the items all get selected, but then they are
somehow unselected as the form posts. Any idea? My Html and .net code
follows:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>test SELECT</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
</HEAD>
<body>

<form id="Form1" method="post" runat="server">

<table>
<tbody>
<tr>
<td>
<SELECT multiple size="20" name="ListBox2" id="ListBox2"
style="WIDTH:350px">
<OPTION selected value="Value 1">Text 1</OPTION>
<OPTION>Text 2</OPTION>
<OPTION>Text 3</OPTION>
<OPTION>Text 4</OPTION>
<OPTION>Text 5</OPTION>
<OPTION>Text 6</OPTION>
<OPTION>Text 7</OPTION>
<OPTION>Final option</OPTION>
</SELECT>
</td>
</tr>
<tr>
<td>
<asp:TextBox id="txtOut" runat="server" Columns="60" Rows="10"
TextMode="MultiLine"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<a href="#" onclick="JavaScript:selectListBox2();">click me</a>
&nbsp;
<asp:Button id="Button1" runat="server"
Text="Button"></asp:Button>
</td>
</tr>
</tbody>
</table>

<script>
<!--
function selectListBox2()
{
var iLoop;
for (iLoop = 0; iLoop < document.Form1.ListBox2.length; iLoop++)
{
document.Form1.ListBox2[iLoop].selected = true;
}
document.Form1.submit();
}
// -->
</script>

</form>

</body>
</HTML>








Public Class test_DualList
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents txtOut As System.Web.UI.WebControls.TextBox

'NOTE: The following placeholder declaration is required by the
Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form
Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
Dim iLoopRows As Int16

If (IsPostBack) Then
txtOut.Text = Request.Form.Item("ListBox2")
Else
Button1.Attributes.Add("onclick",
"JavaScript:selectListBox2();")
End If

End Sub
End Class
 
Reply With Quote
 
 
 
 
bruce barker
Guest
Posts: n/a
 
      03-05-2004
because your anchor is refreshing the page. try:

<a href="javascript:selectListBox2();">click me</a>

-- bruce (sqlwork.com)


"Mad Scientist Jr" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> I'm stuck trying to work with a HTML <SELECT> control and javascript
> (similar to DualList but that control doesn't offer enough options to
> totally control the text on the buttons and control, also I don't have
> c# on this machine to try and modify it).. anyway...
>
> I'm trying to get javascipt to select all items in a <SELECT> control
> and submit the form to an asp.net page. For some reason when the link
> is clicked, you can see the items all get selected, but then they are
> somehow unselected as the form posts. Any idea? My Html and .net code
> follows:
>
>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
> <HTML>
> <HEAD>
> <title>test SELECT</title>
> <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
> <meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
> <meta content="JavaScript" name="vs_defaultClientScript">
> <meta content="http://schemas.microsoft.com/intellisense/ie5"
> name="vs_targetSchema">
> </HEAD>
> <body>
>
> <form id="Form1" method="post" runat="server">
>
> <table>
> <tbody>
> <tr>
> <td>
> <SELECT multiple size="20" name="ListBox2" id="ListBox2"
> style="WIDTH:350px">
> <OPTION selected value="Value 1">Text 1</OPTION>
> <OPTION>Text 2</OPTION>
> <OPTION>Text 3</OPTION>
> <OPTION>Text 4</OPTION>
> <OPTION>Text 5</OPTION>
> <OPTION>Text 6</OPTION>
> <OPTION>Text 7</OPTION>
> <OPTION>Final option</OPTION>
> </SELECT>
> </td>
> </tr>
> <tr>
> <td>
> <asp:TextBox id="txtOut" runat="server" Columns="60" Rows="10"
> TextMode="MultiLine"></asp:TextBox>
> </td>
> </tr>
> <tr>
> <td>
> <a href="#" onclick="JavaScript:selectListBox2();">click me</a>
> &nbsp;
> <asp:Button id="Button1" runat="server"
> Text="Button"></asp:Button>
> </td>
> </tr>
> </tbody>
> </table>
>
> <script>
> <!--
> function selectListBox2()
> {
> var iLoop;
> for (iLoop = 0; iLoop < document.Form1.ListBox2.length; iLoop++)
> {
> document.Form1.ListBox2[iLoop].selected = true;
> }
> document.Form1.submit();
> }
> // -->
> </script>
>
> </form>
>
> </body>
> </HTML>
>
>
>
>
>
>
>
>
> Public Class test_DualList
> Inherits System.Web.UI.Page
>
> #Region " Web Form Designer Generated Code "
>
> 'This call is required by the Web Form Designer.
> <System.Diagnostics.DebuggerStepThrough()> Private Sub
> InitializeComponent()
>
> End Sub
> Protected WithEvents Button1 As System.Web.UI.WebControls.Button
> Protected WithEvents txtOut As System.Web.UI.WebControls.TextBox
>
> 'NOTE: The following placeholder declaration is required by the
> Web Form Designer.
> 'Do not delete or move it.
> Private designerPlaceholderDeclaration As System.Object
>
> Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Init
> 'CODEGEN: This method call is required by the Web Form
> Designer
> 'Do not modify it using the code editor.
> InitializeComponent()
> End Sub
>
> #End Region
>
> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
> 'Put user code to initialize the page here
> End Sub
>
> Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
> As System.EventArgs) Handles Button1.Click
> Dim iLoopRows As Int16
>
> If (IsPostBack) Then
> txtOut.Text = Request.Form.Item("ListBox2")
> Else
> Button1.Attributes.Add("onclick",
> "JavaScript:selectListBox2();")
> End If
>
> End Sub
> End Class



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
That which was sundered and undone shall behold the two made one... Bryan.Burrows@gmail.com Computer Information 0 01-10-2008 09:46 PM
Autoselect in a radio hygum Javascript 11 09-08-2005 07:55 AM
Microsoft TreeView AutoSelect magister ASP .Net 0 09-14-2004 09:33 AM
autoselect all items in <SELECT> control is undone when form submits Mad Scientist Jr Javascript 2 03-06-2004 01:08 PM
Help needed with form submits and Perl handling Robert V Perl 1 07-21-2003 05:00 AM



Advertisments