AutoPostback

Nov 4, 2010 at 8:54 AM

Hi!

I've been using your new version (thanks!) but I've a little problem...

I've a listbox which do autopostback, and then fills Typps HTML Editor with database content. The first item I select works fine, but when I select another one the same content still appear at HTML Editor instead the new database obtained data.

I assume it's because HTMLEditor is sending its content together with listbox autoPostBack and then ignores the upcoming database content.

Sample code:

string strConn = WebConfigurationManager.ConnectionStrings["MyConnection"].ConnectionString;
SqlConnection Conn = new SqlConnection(strConn);
sqlUserName  = "SELECT DISTINCT * from view_TramiteINFO where ID_TramPaso = " + IDPaso;
SqlCommand com = new SqlCommand(sqlUserName, Conn);
dr = com.ExecuteReader();
dr.Read();
MyTyppsEditor.Text = Convert.ToString(dr["PasoText"]); 
dr.Close(); 
Conn.Close(); 

The red line shows where the content should be replaced with database content, but it's not working after the first postback (it works with default VS2010 basic HTMLEditor).

Thanks for any help

James

Coordinator
Nov 4, 2010 at 1:09 PM

Hello, I couldn't reproduce the problem. Following is a simple self contained sample based on your description. As you can note, there's a dropdownlist with autopostback and each time the new value is reflected in the editor. Let me know if I have missed something :

<%@ Page Language="C#" ValidateRequest="false" %>
<%@ Register Assembly="Typps" Namespace="Typps" TagPrefix="cc1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
            "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            UpdateEditor();
        }
    }

    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        UpdateEditor();
    }

    void UpdateEditor()
    {
        string selectedText = DropDownList1.SelectedItem.Text;
        Editor1.Text = selectedText;
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true" 
                OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
            <asp:ListItem Text="a"></asp:ListItem>
            <asp:ListItem Text="b"></asp:ListItem>
            <asp:ListItem Text="c"></asp:ListItem>
        </asp:DropDownList>
        <cc1:Editor ID="Editor1" runat="server">
        </cc1:Editor>
    </div>
    </form>
</body>
</html>