Thanks for your reply.
Here is the source code:
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"
http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
System.Xml.Serialization.XmlSerializer xs = new
System.Xml.Serialization.XmlSerializer(typeof(ArrayList));
ArrayList users = new ArrayList();
ArrayList projs = new ArrayList();
System.IO.FileStream fs = System.IO.File.Open("/projects.xml",
System.IO.FileMode.Open);
projs = xs.Deserialize(fs) as ArrayList;
fs.Close();
xs = new System.Xml.Serialization.XmlSerializer(typeof(ArrayList));
fs = System.IO.File.Open("/users.xml", System.IO.FileMode.Open);
users = xs.Deserialize(fs) as ArrayList;
fs.Close();
while (lstUsers.Items.Count > 0)
lstUsers.Items.Remove(lstUsers.Items[0]);
while (lstProjects.Items.Count > 0)
lstProjects.Items.Remove(lstProjects.Items[0]);
foreach (object o in users)
lstUsers.Items.Add(o as string);
foreach (object o in projs)
lstProjects.Items.Add(o as string);
fs.Close();
}
protected void btnGenerate_Click(object sender, EventArgs e)
{
// here is the problem: selecteditem.text is null
string s = string.Format("c:\\{0}\\{1}.{2}", lstProjects.SelectedItem.Text,
lstUsers.SelectedItem.Text, txtHours.Text);
System.IO.FileStream fs = System.IO.File.Open(s,
System.IO.FileMode.OpenOrCreate,
System.IO.FileAccess.Write);
fs.Close();
}
</script>
<html xmlns="
http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ListBox ID="lstProjects" runat="server"></asp:ListBox>
<asp:ListBox ID="lstUsers" runat="server"></asp:ListBox>
<asp:Label ID="txtHours" runat="server" Text="Hours:"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><asp:Button
ID="btnGenerate"
runat="server" Text="Generate" OnClick="btnGenerate_Click" />
<asp:Label ID="Label1" runat="server" Height="15px"
Width="475px"></asp:Label>
</div>
</form>
</body>
</html>
Eliyahu Goldin said:
Ohad,
Are you sure you are not re-populating the listbox on postback? In other
words, are you checking IsPostBack property?
Eliyahu
item
in