-
-
After 4 hours of figuring out why my ASP.Net page disappear into white space after selecting an item in a dropdown list I have finally found out that IE 6 have some strange bug regarding dropdown lists and Frames.
Here's how to solve it.
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>DropDownListError</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5";>
<script language=javascript>
function check()
{
if(document.all("hdFlag").value == "1")
{
document.all("lstMain").disabled = true;
}
}
function setflag()
{
document.all("hdFlag").value = "1";
}
</script>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<table width="500" align="center">
<tr>
<td>
<asp:Label id="lblMessage" runat="server"></asp:Label><input
type="hidden" id="hdFlag" runat="server" value="0" NAME="hdFlag"></td>
</tr>
<tr>
<td>
<asp:DropDownList id="lstMain" runat="server" AutoPostBack="True">
<asp:ListItem Value="ItemA" Selected="True">ItemA</asp:ListItem>
<asp:ListItem Value="ItemB">ItemB</asp:ListItem>
<asp:ListItem Value="ItemC">ItemC</asp:ListItem>
<asp:ListItem Value="ItemD">ItemD</asp:ListItem>
</asp:DropDownList>
<select ></select>
</td>
</tr>
</table>
</form>
</body>
</HTML>
Code Behind Class
public class DropDownListError : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DropDownList lstMain;
protected System.Web.UI.HtmlControls.HtmlInputHidden hdFlag;
protected System.Web.UI.WebControls.Label lblMessage;
private void Page_Load(object sender, System.EventArgs e)
{
lstMain.Attributes.Add("onchange","setflag();");
lstMain.Attributes.Add("onmousedown","check();");
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.lstMain.SelectedIndexChanged += new
System.EventHandler(this.lstMain_SelectedIndexChanged);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void lstMain_SelectedIndexChanged(object sender, System.EventArgs
e)
{
System.Threading.Thread.Sleep(1000*4);
lblMessage.Text = "SelectIndex is changed to " + lstMain.SelectedIndex +
"at " + DateTime.Now.ToLongTimeString();
hdFlag.Value = "0";
}
}
What you basically doing here is forcing client side JavaScript events to set a flag on submission of the page. The script check for the flag, disables the dropdown box, sleeps for a few seconds, does your code change and then reloads the page. Why this works? Don’t know.
http://www.dotnet247.com/247reference/msgs/40/204635.aspx
-
-
We all get into the position where we have either not set “copy local” to true, or we have the wrong versions of dependant dll's with us during an installation at a client. So, what do you do? You simply do a dependency redirect. Dependency redirect is a piece of markup that goes into your config file and tells your application to rather use another version of the assemblies it is looking for. Below follows an example
The following example shows how to redirect one assembly version to another
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="myAssembly"
publicKeyToken="32ab4ba45e0a69a1"
culture="neutral" />
<bindingRedirect oldVersion="1.0.0.0"
newVersion="2.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
-
-
For those of you who do not know this yet, SA has a new search engine.
http://www.funnel.co.za
-
-
After reading this article, I still prefer keeping the Javascript in a seperate .js file and calling the methods client side.
http://msdn.microsoft.com/asp.net/articles/client/default.aspx?pull=/library/en-us/dnaspp/html/aspnet-usingjavascript.asp
-
-
The LifeWorks set of articles is going to be moved into a newsletter format. I'm removing them from this blog, to keep the writings in the blog mainly development orientated. If you are interested in receiving life works, you can mail me: riaan.snyders@gmail.com