Sorry for the basic inquiry, but I have struggled with this for a while and have no clues.
I am using VS 2008 to write a vb.net app that runs on Windows IIS Server 2008. I have done asp for years prior and am now learning .net.
I am trying to act upon a listbox selection.
This is my code:
listtest.aspx
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="listtest.aspx.vb" Inherits="listtest" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server" method="post">
<div>
<%
lsttest.Items.Add("one")
lsttest.Items.Add("two")
lsttest.Items.Add("3")
%>
<asp:ListBox ID="lsttest" runat="server"></asp:ListBox>
<br />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<asp:Button ID="Button1" runat="server" Text="Button" />
</div>
</form>
</body>
</html>
listtest.aspx.vb
Partial Class listtest
Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Response.Write("selectedindex is " & lsttest.SelectedIndex & "<br/>")
Response.Write(TextBox1.Text)
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
End Class
You may run it here:
http://jhdpetro.com:89/listtest.aspx
Make a selection and enter some text into the textbox.
The selected index always returns -1 although the textbox data is available. In addition, the selected item in the listbox is cleared when the page refreshes.
Why can't I access the selected item is there a simple fix to this?
Thank you for reading!
dj
I am using VS 2008 to write a vb.net app that runs on Windows IIS Server 2008. I have done asp for years prior and am now learning .net.
I am trying to act upon a listbox selection.
This is my code:
listtest.aspx
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="listtest.aspx.vb" Inherits="listtest" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server" method="post">
<div>
<%
lsttest.Items.Add("one")
lsttest.Items.Add("two")
lsttest.Items.Add("3")
%>
<asp:ListBox ID="lsttest" runat="server"></asp:ListBox>
<br />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<asp:Button ID="Button1" runat="server" Text="Button" />
</div>
</form>
</body>
</html>
listtest.aspx.vb
Partial Class listtest
Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Response.Write("selectedindex is " & lsttest.SelectedIndex & "<br/>")
Response.Write(TextBox1.Text)
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
End Class
You may run it here:
http://jhdpetro.com:89/listtest.aspx
Make a selection and enter some text into the textbox.
The selected index always returns -1 although the textbox data is available. In addition, the selected item in the listbox is cleared when the page refreshes.
Why can't I access the selected item is there a simple fix to this?
Thank you for reading!
dj
Last edited: