我网站上的搜索表单在 IE 上的行为错误(我尝试过 IE8 和 IE7) 当我单击链接按钮或复选框时,会启动回发并重置所有字段。所有以前找到的结果也被重置,页面变成空的,就像第一次加载一样。
这不会发生在 FF 和 Chrome 上。
如果我运行 Fiddler 来查看发生了什么,页面运行得非常好,并且回发会返回我所有的数据。我猜 Fiddler 纠正了它,所以我看不出 IE 发送到服务器的查询有什么问题。
现在,让我们看看代码。首先,调用 .Net 内容的 HTML 页面:
<iframe width="605" scrolling="AUTO" height="6000" frameborder="NO" marginwidth="0" marginheight="0" src="http://[MYSERVERNAME]/xml/dialog/rechercher.aspx?L=FR" id="iframe_"></iframe>
然后,ASPX 页面文件“rechercher.aspx”:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="~/xml/Dialog/rechercher.aspx.cs" Inherits="xml_Dialog_rechercher" %>
<!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>Recherche</title>
<link rel="stylesheet" href="css/screen.css" />
<script type="text/javascript" src="js/dialog.js"></script>
<!-- other js calls -->
</head>
<body style="background-image:url('/lib_central/images/ACTIV/common/bgd_main.gif');background-repeat:repeat-y;">
<form runat="server">
<!--
some presentation code
...
-->
<!-- sample of one of the search fields -->
<label for="motsClefs" class="bold"><% Response.Write(get_label("motcle")); %></label><br />
<asp:TextBox ID="rech_kw" runat="server" value="" ForeColor="#999999" Width="250"></asp:TextBox>
<!-- The validation field -->
<asp:LinkButton ID="rech_valide" OnClick="lancer_recherche" runat="server" CssClass="boutons rechercher inlineBlk" >
<span class="rechercher"><span class="alt_text">rechercher</span></span></asp:LinkButton>
<br class="clear" />
<%-- Results displaying --%>
<div ID="resultats" class="contentDia alignementBlk" runat="server"></div>
<!--
some footer code
...
-->
<!-- Tell the parent page to stretch according to the number of results -->
<script type="text/javascript">
$('#iframe_666', window.parent.document).height(100+$(".contentDialogue").height());
</script>
</form>
</body>
</html>
最后是背后的.Net代码:
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Xml.Linq;
using UsersData;
public partial class xml_Dialog_rechercher : System.Web.UI.Page
{
string keyword = ""; // Champ de saisie texte
List<DLG_Questions> list_q;
public string lang;
// Au chargement de la page
protected void Page_Load(object sender, EventArgs e)
{
}
// If the form validation button is clicked
protected void lancer_recherche(object sender, EventArgs e)
{
// If user typed something in search field
if (get_filters())
{
// Query the data layer to retrieve what is searched
this.list_q = DialogManager.recherche(this.keyword);
// Display resultst
if (this.list_q.Count == 0)
{
resultats.InnerHtml = "no results";
}
else
{
resultats.InnerHtml = display_question_list();
}
}
}
// "Read" input field controls.
// If all empty => return FALSE
// if some contains data => Save that data and return TRUE
protected bool get_filters()
{
// ...
return ret;
}
// Return a HTML of the list of themes searched
public string display_question_list(){
// ...
}
// Internationnalisation allow me to display labels in different languages
protected string get_label(String cle)
{
// ...
}
}