Good day!
I have got some comboboxes on page. Some of them has property autopostback=true, enother autopostback=false.
When I select (for the first time) a value of combobox with autopostback=true, good looking page (you can see it at the picture 1) becomes bad looking =((( (picture 2). But the html still being the same :(
It happens only in Firefox, Opera, Google Chrome, Safari. In ie 6, ie 7, ie 8 everything is allright.
There is my code below (css is here: http://aptekaural.ru/tmp/style.css and here: http://aptekaural.ru/tmp/style_ie.css ).
What do I do wrong?
Site.master
_____________________________________________________
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site.master.cs" Inherits="Pharm.New.Site" %>
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<%@ Register Src="~/Controls/MainMenu.ascx" TagName="MainMenu" TagPrefix="uc1" %>
<%@ Register Src="~/Controls/TopMenu.ascx" TagName="TopMenu" TagPrefix="uc2" %>
<%@ Register Src="~/Controls/Footer.ascx" TagName="Footer" TagPrefix="uc3" %>
<!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>
<link href="/Style/style.css" rel="stylesheet" type="text/css" />
<!--[if IE ]>
<link href="/Style/style_ie.css" rel="stylesheet" type="text/css" />
<script language="javascript" src="/js/width.js"></script>
<![endif]-->
<!--[if IE 8 ]>
<link href="/Style/style.css" rel="stylesheet" type="text/css" />
<![endif]-->
<!--свой скин для телерика-->
<link href="FarmPortal/Grid.FarmPortal.css" rel="stylesheet" type="text/css" />
<link href="FarmPortal/ComboBox.FarmPortal.css" rel="Stylesheet" type="text/css" />
<link href="FarmPortal/Input.FarmPortal.css" rel="Stylesheet" type="text/css" />
<style type="text/css">
.highlight {text-decoration:none; font-weight:bold; color: red;}
</style>
<script type="text/javascript">
</script>
</head>
<body onload="">
<form runat="server" >
<telerik:RadScriptManager ID="RadScriptManager1" runat="server" EnablePageMethods="true"/>
<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server" >
<script type="text/javascript">
$(document).ready(function () {
var combo =<%=cbRegion.ClientID%>;
combo.FixUp(combo.InputDomElement,true);
var combo1 =<%=cbCity.ClientID%>;
combo1.FixUp(combo1.InputDomElement,true);
});
</script>
</telerik:RadCodeBlock>
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
<AjaxSettings>
<telerik:AjaxSetting AjaxControlID="cbRegion">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="cbCity" />
</UpdatedControls>
</telerik:AjaxSetting>
<telerik:AjaxSetting AjaxControlID="cbCity">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="cbCity" />
</UpdatedControls>
</telerik:AjaxSetting>
</AjaxSettings>
</telerik:RadAjaxManager>
<div id="glav">
<table cellpadding="0px" cellspacing="0px" style="margin:0px; padding:0px; height: 100%; min-height: 100%; min-width: 100%;" >
<tr>
<td>
<div class="h_r">
<div class="h_l">
<div class="header">
<div class="m_r">
<div class="m_l">
<div class="menu">
<uc2:TopMenu runat="server" ID="TopMenu"/>
</div>
</div>
</div>
<div class="main">
<div class="center1">
<div id="poisk">
<div id="geo">
вы находитесь в г. Екатеринбурге, если мы ошиблись
<a href="#">поправьте нас</a>
</div>
<asp:Panel runat="server" ID="pnlLogic" DefaultButton="lbtSearch">
<table>
<tr>
<td>
<telerik:RadComboBox ID="cbRegion" Width="162px" EnableTextSelection="False" runat="server" onselectedindexchanged="cbRegion_SelectedIndexChanged" AutoPostBack="true" Skin="Default" />
</td>
<td>
<telerik:RadComboBox ID="cbCity" Width="150px" EnableTextSelection="False" runat="server" AutoPostBack="true" onselectedindexchanged="cbCity_SelectedIndexChanged" Skin="Default" />
</td>
<td>
<telerik:RadComboBox ID="cbTypeSearch" Width="150px" runat="server"/>
</td>
</tr>
<tr align="center">
<td colspan="3">
<telerik:RadTextBox runat="server" ID="tbSearch" Width="100%" Height="16"/>
</td>
</tr>
<tr align="center">
<td colspan="2" >
<asp:LinkButton runat="server" ID="lbtSearch" Text="_______" CssClass="poisk_linkbutton" Width="60px" onclick="btSearch_Click" />
</td>
<td align="right">
<!--<a id="sss" href="#">расширенный поиск</a>-->
</td>
</tr>
</table>
</asp:Panel>
</div>
</div>
</div>
<div class="left"><a id="logo" href="./">
Единая<br />
Фармацевтическая<br />
Справка</a>
</div>
<div class="right tel">
<a href="http://cabinet.aptekaural.ru"> вход в личный кабинет</a><br />
(343) 123 45 67
</div>
</div>
</div>
</div>
</td>
</tr>
<tr>
<td>
<div id="linkmenu">
<uc1:MainMenu runat="server" ID="MainMenu"/>
</div>
</td>
</tr>
<tr>
<td>
<table cellpadding="0px" cellspacing="0px" style="margin:0px; padding:0px; height: 100%; min-height: 100%;" width="100%" >
<tr>
<td id="left" valign="top">
<asp:ContentPlaceHolder ID="phLeft" runat="server"/>
</td>
<td id="center" valign="top">
<asp:ContentPlaceHolder ID="phCenter" runat="server"/>
</td>
<td id="right" valign="top">
<asp:ContentPlaceHolder ID="phRight" runat="server"/>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<uc3:Footer runat="server" ID="Footer" />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
Site.master.cs
_____________________________________________________
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using Clients.Core.DTO.DTO;
using Pharm.New.Code;
namespace Pharm.New
{
public partial class Site : MasterPage
{
private static readonly string[] typeSearch = {"Товары", "Аптеки", "Медицински учреждения"};
protected void Page_Load(object sender, EventArgs e)
{
Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoStore();
cbTypeSearch.SelectedIndexChanged += (o, ev) =>
{
Session["typeSearch"] = cbTypeSearch.SelectedValue;
};
}
protected void Page_Init(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindRegions();
if (Session["SearchString"] != null)
tbSearch.Text = (string)Session["SearchString"];
}
}
protected void Page_Prerender(object sender, EventArgs e)
{
RegisterStartupScripts();
}
public int CityId
{
get {
return String.IsNullOrEmpty(cbCity.SelectedValue) ? 0 : Int32.Parse(cbCity.SelectedValue);
}
}
public string CityName
{
get
{
return cbCity.SelectedItem.Text;
}
}
public string SearchString
{
get { return tbSearch.Text; }
}
private void BindRegions()
{
var cap = new CAPServiceHelper();
cbRegion.DataSource = cap.GetRegions().OrderBy(r => r.Name).ToList();
cbRegion.DataTextField = "Name";
cbRegion.DataValueField = "Id";
cbRegion.DataBind();
cbRegion.SelectedIndex =
cbRegion.FindItemIndexByValue(Request.Cookies["region"] != null
? Request.Cookies["region"].Value
: Constants.TyumenRegionId.ToString());
cbCity.SelectedIndex = cbCity.FindItemIndexByValue(Request.Cookies["city"] != null ? Request.Cookies["city"].Value : Constants.TyumenId.ToString());
cbRegion_SelectedIndexChanged(cbCity, null);
cbTypeSearch.DataSource = typeSearch;
cbTypeSearch.DataBind();
if (Session["city"] != null)
cbCity.SelectedIndex = cbCity.FindItemIndexByValue((string)Session["city"]);
if (Session["typeSearch"] != null)
cbTypeSearch.SelectedIndex = cbTypeSearch.FindItemIndexByValue((string)Session["typeSearch"]);
}
protected void cbRegion_SelectedIndexChanged(object o, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
{
var cap = new CAPServiceHelper();
cbCity.DataSource = cap.GetCities().Where(c => c.Region.Id == Convert.ToInt32(cbRegion.SelectedValue)).OrderBy(r => r.Name).ToList();
cbCity.DataTextField = "Name";
cbCity.DataValueField = "Id";
cbCity.DataBind();
int idx = ((List<CityDTO>)cbCity.DataSource).FindIndex(s => s.IsCapital);
if (idx != -1)
cbCity.SelectedIndex = idx;
if (cbCity.SelectedValue != null)
{
Response.Cookies["city"].Value = cbCity.SelectedValue;
Response.Cookies["city"].Expires = DateTime.Now.AddYears(3);
}
if (cbRegion.SelectedValue != null)
{
Response.Cookies["region"].Value = cbRegion.SelectedValue;
Response.Cookies["region"].Expires = DateTime.Now.AddYears(3);
}
}
protected void cbCity_SelectedIndexChanged(object o, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
{
if (cbCity.SelectedValue != null)
{
Response.Cookies["city"].Value = cbCity.SelectedValue;
Response.Cookies["city"].Expires = DateTime.Now.AddYears(3);
Session["city"] = cbCity.SelectedValue;
}
}
protected void btSearch_Click(object sender, EventArgs e)
{
Session["SearchString"] = tbSearch.Text;
if (cbTypeSearch.SelectedItem.Text == "Товары")
Response.Redirect("./Product.aspx");
else if (cbTypeSearch.SelectedItem.Text=="Аптеки")
Response.Redirect("./Pharmacy.aspx");
}
private void RegisterStartupScripts()
{
var sb = new StringBuilder();
sb.Append(" function addClickFunction(id) {{ ");
sb.Append(" var b = document.getElementById(id); ");
sb.Append(" if (b && typeof(b.click) == 'undefined') b.click = function() {{ ");
sb.Append(" var result = true; if (b.onclick) result = b.onclick(); ");
sb.Append(" if (typeof(result) == 'undefined' || result) {{ eval(b.getAttribute('href')); }} ");
sb.Append(" }}}}; ");
const string addClickScript = "addClickFunction('{0}');";
var clickScript = String.Format(addClickScript, lbtSearch.ClientID);
ScriptManager.RegisterStartupScript(this, GetType(), "addClickFunctionScript", sb.ToString(),true);
ScriptManager.RegisterStartupScript(this, GetType(), "click_" + lbtSearch.ClientID, clickScript, true);
}
public string Title
{
get { return Page.Title; }
set { Page.Title = value; }
}
}
}
I have got some comboboxes on page. Some of them has property autopostback=true, enother autopostback=false.
When I select (for the first time) a value of combobox with autopostback=true, good looking page (you can see it at the picture 1) becomes bad looking =((( (picture 2). But the html still being the same :(
It happens only in Firefox, Opera, Google Chrome, Safari. In ie 6, ie 7, ie 8 everything is allright.
There is my code below (css is here: http://aptekaural.ru/tmp/style.css and here: http://aptekaural.ru/tmp/style_ie.css ).
What do I do wrong?
Site.master
_____________________________________________________
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site.master.cs" Inherits="Pharm.New.Site" %>
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<%@ Register Src="~/Controls/MainMenu.ascx" TagName="MainMenu" TagPrefix="uc1" %>
<%@ Register Src="~/Controls/TopMenu.ascx" TagName="TopMenu" TagPrefix="uc2" %>
<%@ Register Src="~/Controls/Footer.ascx" TagName="Footer" TagPrefix="uc3" %>
<!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>
<link href="/Style/style.css" rel="stylesheet" type="text/css" />
<!--[if IE ]>
<link href="/Style/style_ie.css" rel="stylesheet" type="text/css" />
<script language="javascript" src="/js/width.js"></script>
<![endif]-->
<!--[if IE 8 ]>
<link href="/Style/style.css" rel="stylesheet" type="text/css" />
<![endif]-->
<!--свой скин для телерика-->
<link href="FarmPortal/Grid.FarmPortal.css" rel="stylesheet" type="text/css" />
<link href="FarmPortal/ComboBox.FarmPortal.css" rel="Stylesheet" type="text/css" />
<link href="FarmPortal/Input.FarmPortal.css" rel="Stylesheet" type="text/css" />
<style type="text/css">
.highlight {text-decoration:none; font-weight:bold; color: red;}
</style>
<script type="text/javascript">
</script>
</head>
<body onload="">
<form runat="server" >
<telerik:RadScriptManager ID="RadScriptManager1" runat="server" EnablePageMethods="true"/>
<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server" >
<script type="text/javascript">
$(document).ready(function () {
var combo =<%=cbRegion.ClientID%>;
combo.FixUp(combo.InputDomElement,true);
var combo1 =<%=cbCity.ClientID%>;
combo1.FixUp(combo1.InputDomElement,true);
});
</script>
</telerik:RadCodeBlock>
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
<AjaxSettings>
<telerik:AjaxSetting AjaxControlID="cbRegion">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="cbCity" />
</UpdatedControls>
</telerik:AjaxSetting>
<telerik:AjaxSetting AjaxControlID="cbCity">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="cbCity" />
</UpdatedControls>
</telerik:AjaxSetting>
</AjaxSettings>
</telerik:RadAjaxManager>
<div id="glav">
<table cellpadding="0px" cellspacing="0px" style="margin:0px; padding:0px; height: 100%; min-height: 100%; min-width: 100%;" >
<tr>
<td>
<div class="h_r">
<div class="h_l">
<div class="header">
<div class="m_r">
<div class="m_l">
<div class="menu">
<uc2:TopMenu runat="server" ID="TopMenu"/>
</div>
</div>
</div>
<div class="main">
<div class="center1">
<div id="poisk">
<div id="geo">
вы находитесь в г. Екатеринбурге, если мы ошиблись
<a href="#">поправьте нас</a>
</div>
<asp:Panel runat="server" ID="pnlLogic" DefaultButton="lbtSearch">
<table>
<tr>
<td>
<telerik:RadComboBox ID="cbRegion" Width="162px" EnableTextSelection="False" runat="server" onselectedindexchanged="cbRegion_SelectedIndexChanged" AutoPostBack="true" Skin="Default" />
</td>
<td>
<telerik:RadComboBox ID="cbCity" Width="150px" EnableTextSelection="False" runat="server" AutoPostBack="true" onselectedindexchanged="cbCity_SelectedIndexChanged" Skin="Default" />
</td>
<td>
<telerik:RadComboBox ID="cbTypeSearch" Width="150px" runat="server"/>
</td>
</tr>
<tr align="center">
<td colspan="3">
<telerik:RadTextBox runat="server" ID="tbSearch" Width="100%" Height="16"/>
</td>
</tr>
<tr align="center">
<td colspan="2" >
<asp:LinkButton runat="server" ID="lbtSearch" Text="_______" CssClass="poisk_linkbutton" Width="60px" onclick="btSearch_Click" />
</td>
<td align="right">
<!--<a id="sss" href="#">расширенный поиск</a>-->
</td>
</tr>
</table>
</asp:Panel>
</div>
</div>
</div>
<div class="left"><a id="logo" href="./">
Единая<br />
Фармацевтическая<br />
Справка</a>
</div>
<div class="right tel">
<a href="http://cabinet.aptekaural.ru"> вход в личный кабинет</a><br />
(343) 123 45 67
</div>
</div>
</div>
</div>
</td>
</tr>
<tr>
<td>
<div id="linkmenu">
<uc1:MainMenu runat="server" ID="MainMenu"/>
</div>
</td>
</tr>
<tr>
<td>
<table cellpadding="0px" cellspacing="0px" style="margin:0px; padding:0px; height: 100%; min-height: 100%;" width="100%" >
<tr>
<td id="left" valign="top">
<asp:ContentPlaceHolder ID="phLeft" runat="server"/>
</td>
<td id="center" valign="top">
<asp:ContentPlaceHolder ID="phCenter" runat="server"/>
</td>
<td id="right" valign="top">
<asp:ContentPlaceHolder ID="phRight" runat="server"/>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<uc3:Footer runat="server" ID="Footer" />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
Site.master.cs
_____________________________________________________
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using Clients.Core.DTO.DTO;
using Pharm.New.Code;
namespace Pharm.New
{
public partial class Site : MasterPage
{
private static readonly string[] typeSearch = {"Товары", "Аптеки", "Медицински учреждения"};
protected void Page_Load(object sender, EventArgs e)
{
Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoStore();
cbTypeSearch.SelectedIndexChanged += (o, ev) =>
{
Session["typeSearch"] = cbTypeSearch.SelectedValue;
};
}
protected void Page_Init(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindRegions();
if (Session["SearchString"] != null)
tbSearch.Text = (string)Session["SearchString"];
}
}
protected void Page_Prerender(object sender, EventArgs e)
{
RegisterStartupScripts();
}
public int CityId
{
get {
return String.IsNullOrEmpty(cbCity.SelectedValue) ? 0 : Int32.Parse(cbCity.SelectedValue);
}
}
public string CityName
{
get
{
return cbCity.SelectedItem.Text;
}
}
public string SearchString
{
get { return tbSearch.Text; }
}
private void BindRegions()
{
var cap = new CAPServiceHelper();
cbRegion.DataSource = cap.GetRegions().OrderBy(r => r.Name).ToList();
cbRegion.DataTextField = "Name";
cbRegion.DataValueField = "Id";
cbRegion.DataBind();
cbRegion.SelectedIndex =
cbRegion.FindItemIndexByValue(Request.Cookies["region"] != null
? Request.Cookies["region"].Value
: Constants.TyumenRegionId.ToString());
cbCity.SelectedIndex = cbCity.FindItemIndexByValue(Request.Cookies["city"] != null ? Request.Cookies["city"].Value : Constants.TyumenId.ToString());
cbRegion_SelectedIndexChanged(cbCity, null);
cbTypeSearch.DataSource = typeSearch;
cbTypeSearch.DataBind();
if (Session["city"] != null)
cbCity.SelectedIndex = cbCity.FindItemIndexByValue((string)Session["city"]);
if (Session["typeSearch"] != null)
cbTypeSearch.SelectedIndex = cbTypeSearch.FindItemIndexByValue((string)Session["typeSearch"]);
}
protected void cbRegion_SelectedIndexChanged(object o, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
{
var cap = new CAPServiceHelper();
cbCity.DataSource = cap.GetCities().Where(c => c.Region.Id == Convert.ToInt32(cbRegion.SelectedValue)).OrderBy(r => r.Name).ToList();
cbCity.DataTextField = "Name";
cbCity.DataValueField = "Id";
cbCity.DataBind();
int idx = ((List<CityDTO>)cbCity.DataSource).FindIndex(s => s.IsCapital);
if (idx != -1)
cbCity.SelectedIndex = idx;
if (cbCity.SelectedValue != null)
{
Response.Cookies["city"].Value = cbCity.SelectedValue;
Response.Cookies["city"].Expires = DateTime.Now.AddYears(3);
}
if (cbRegion.SelectedValue != null)
{
Response.Cookies["region"].Value = cbRegion.SelectedValue;
Response.Cookies["region"].Expires = DateTime.Now.AddYears(3);
}
}
protected void cbCity_SelectedIndexChanged(object o, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
{
if (cbCity.SelectedValue != null)
{
Response.Cookies["city"].Value = cbCity.SelectedValue;
Response.Cookies["city"].Expires = DateTime.Now.AddYears(3);
Session["city"] = cbCity.SelectedValue;
}
}
protected void btSearch_Click(object sender, EventArgs e)
{
Session["SearchString"] = tbSearch.Text;
if (cbTypeSearch.SelectedItem.Text == "Товары")
Response.Redirect("./Product.aspx");
else if (cbTypeSearch.SelectedItem.Text=="Аптеки")
Response.Redirect("./Pharmacy.aspx");
}
private void RegisterStartupScripts()
{
var sb = new StringBuilder();
sb.Append(" function addClickFunction(id) {{ ");
sb.Append(" var b = document.getElementById(id); ");
sb.Append(" if (b && typeof(b.click) == 'undefined') b.click = function() {{ ");
sb.Append(" var result = true; if (b.onclick) result = b.onclick(); ");
sb.Append(" if (typeof(result) == 'undefined' || result) {{ eval(b.getAttribute('href')); }} ");
sb.Append(" }}}}; ");
const string addClickScript = "addClickFunction('{0}');";
var clickScript = String.Format(addClickScript, lbtSearch.ClientID);
ScriptManager.RegisterStartupScript(this, GetType(), "addClickFunctionScript", sb.ToString(),true);
ScriptManager.RegisterStartupScript(this, GetType(), "click_" + lbtSearch.ClientID, clickScript, true);
}
public string Title
{
get { return Page.Title; }
set { Page.Title = value; }
}
}
}