0

我有一个带有 3 个下拉列表和文本框的小页面。我的目标是在每个下拉框(或任何组合)中选择一个值,然后在回发后将所选值设置为上次搜索的值。问题之一是 1. 在 IE 中的每次选择之后,页面都会回发(显然),即使添加了启用视图状态的属性,下拉列表也不会保留所选值。

 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="QSerch.aspx.cs" Inherits="QSerch"
    EnableViewState="true" EnableEventValidation="true" EnableViewStateMac="true"%>

<%@ Register Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    Namespace="System.Web.UI" TagPrefix="asp" %>
<!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></title>
    <style type="text/css">
        .ddlstl
        {
            font-size: 13px;
            font-family: Arial;
        }
        #Iframe1
        {
            height: 700px;
            width: 540px;
        }
        .style2
        {
            width: 243px;
        }
    </style>
</head>
<body dir="rtl">
    <form id="form1" runat="server" enableviewstate="true">
    <asp:ScriptManager ID="ScriptManager1" runat="server" EnableScriptGlobalization="True"
        EnablePartialRendering="true" LoadScriptsBeforeUI="false" ScriptMode="Release">
    </asp:ScriptManager>
    <div style="float: right; width: 28px;">
        &nbsp;</div>
    <div style="text-align: right; float: right;">
        <table border="0" cellpadding="0" cellspacing="0">
            <tr>
                <td>
                    <table border="0">
                        <tr>
                            <td style="width: 170px;">
                                <asp:DropDownList ID="ddlMec" runat="server" AutoPostBack="True" CssClass="ddlstl"
                                    Height="22px" Width="160px" EnableViewState="true" OnSelectedIndexChanged="ddlMec_SelectedIndexChanged">
                                </asp:DropDownList>
                            </td>
                        </tr>
                        <tr>
                            <td style="width: 20px;">
                                <asp:DropDownList ID="ddlTMec" runat="server" AutoPostBack="True" CssClass="ddlstl"
                                    Height="22px" Width="160px" OnSelectedIndexChanged="ddlTMec_SelectedIndexChanged"
                                    EnableViewState="true">
                                    <asp:ListItem Value="-1">בחר תפקיד</asp:ListItem>
                                </asp:DropDownList>
                            </td>
                        </tr>
                        <tr>
                            <td style="width: 170px;">
                                <asp:DropDownList ID="ddlArea" runat="server" AutoPostBack="True" CssClass="ddlstl"
                                    DataSourceID="adsArea" DataTextField="name_area" DataValueField="id_area" Height="22px"
                                    Width="160px" OnSelectedIndexChanged="ddlArea_SelectedIndexChanged" AppendDataBoundItems="true"
                                    EnableViewState="true">
                                    <asp:ListItem Value="-1" Text="בחר איזור"></asp:ListItem>
                                </asp:DropDownList>
                                <asp:AccessDataSource ID="adsArea" runat="server" DataFile="~/App_Data/Adam.mdb"
                                    SelectCommand="SELECT [id_area], [name_area] FROM [table_area] ORDER BY [name_area]">
                                </asp:AccessDataSource>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <asp:TextBox runat="server" Text="חיפוש חופשי" ID="txtFreeText" Style="font-size: 12px;
                                    height: 15px; width: 151px" />
                                <%--<input type="text" value="חיפוש חופשי" onfocus="deleteFreeText()" id="FreeText" name="FreeText"
                                            style="font-size: 12px; height: 15px; width: 151px" runat="server" />--%>
                                <br />
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td align="right">
                    <asp:UpdatePanel ID="UpdatePanel2" runat="server" RenderMode="Inline" UpdateMode="Conditional">
                        <ContentTemplate>
                            <iframe id="Iframe1" runat="server" frameborder="0" name="Iframe1" scrolling="no"
                                width="360px" src="" style="overflow: auto"></iframe>
                        </ContentTemplate>
                    </asp:UpdatePanel>
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>


    protected void Page_Load(object sender, EventArgs e)
    {
        TextBox tb = (TextBox)FindControl("txtFreeText");
        tb.Attributes.Add("onfocus", "this.value = ''");
        if (!Page.IsPostBack)
        {
            LoadProffesion();
        }
    }
4

2 回答 2

0

前两个下拉列表 (id=ddlMec & id=ddlTMec) 没有任何与之相关的数据。希望它会在页面加载期间绑定。

假设您必须在第三个下拉列表(id:ddlArea)上遇到问题,这可能是由于您正在使用数据源控件绑定数据。所以每次页面加载时,它都会重新填充数据并且所选项目会丢失。

为了解决这个问题,请尝试在页面加载时绑定下拉列表,并通过 Page.IsPostBacK 属性的帮助来控制它来防止覆盖。

于 2012-09-03T07:26:06.253 回答
0

只需从标签中删除 AutoPostBack="True" 即可。

DropDownList 不需要 AutoPostBack。

于 2012-09-03T07:31:24.143 回答