Postback problem?

Discussion in 'ASP .Net' started by Jerome, Aug 18, 2005.

  1. Jerome

    Jerome Guest

    The selected item is always lost when I submit the page ... why??

    Any help is greatly appreciated!

    Here's my code:
    **************

    <%@ Page Language="VB" ContentType="text/html"
    ResponseEncoding="iso-8859-1" %>
    <%@ Import Namespace="System.Data.Sqlclient" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <script runat="server">

    Dim strConString as String = ConfigurationSettings.AppSettings("conString")

    Sub Page_Load

    If Not IsPostBack then

    Dim conRubriques as SQLConnection
    Dim cmdSelect as SQLCommand
    Dim dtrRubriques as SqlDataReader

    conRubriques= New SqlConnection(strConString)
    conRubriques.Open()
    cmdSelect= New SqlCommand("SELECT dbo.tVisites.IDRubrique,
    dbo.tVisites.VisiteOrdre, dbo.tVisites.VisiteNom, [NomRubrique] + ': ' +
    [VisiteNom] AS Visite, dbo.tVisites.Internet FROM dbo.tVisites INNER
    JOIN dbo.tRubriques ON dbo.tVisites.IDRubrique =
    dbo.tRubriques.IDRubrique ORDER BY dbo.tVisites.VisiteOrdre", conRubriques)
    dtrRubriques = cmdSelect.ExecuteReader()
    listbox1.DataSource= dtrRubriques
    listbox1.DataValueField = "IDRubrique"
    listbox1.DataTextField = "Visite"
    listbox1.DataBind()
    dtrRubriques.Close()
    conRubriques.Close()

    End If

    End Sub

    Sub MergeActiv(s as object, e as eventargs)

    textbox1.text=listbox1.SelectedItem.Text

    End sub

    </script>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    </head>
    <body>
    <form runat="server">
    <p>
    <asp:ListBox ID="ListBox1" runat="server" SelectionMode="single"
    Rows="5"></asp:ListBox>
    </p>
    <p>
    <asp:Button ID="Button1" runat="server" Text="Save"
    OnClick="MergeActiv" /></p>
    <p>
    <asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine"
    Columns="200" />
    </p>
    </form>
    </body>
    </html>
    Jerome, Aug 18, 2005
    #1
    1. Advertising

  2. Jerome

    Jerome Guest

    Re: Postback problem? - Update -

    The selected item is not really lost, in fact the page always defaults
    to the first item in the list and then copies it to my textbox! Even if
    I had the third one selected for example.

    any ideas?
    Jerome, Aug 18, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Psych971
    Replies:
    5
    Views:
    4,595
    bruce barker
    Dec 17, 2004
  2. =?Utf-8?B?Q2hhZA==?=

    Postback not being set to True on first postback

    =?Utf-8?B?Q2hhZA==?=, Apr 4, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    484
    =?Utf-8?B?Q2hhZA==?=
    Apr 4, 2005
  3. gce
    Replies:
    2
    Views:
    1,695
  4. Jacky Chau
    Replies:
    2
    Views:
    2,023
    Ninjamyst
    Jun 8, 2005
  5. Fabio Mastria
    Replies:
    5
    Views:
    4,328
    TechMCAD13
    Jan 30, 2008
Loading...

Share This Page