Thursday, August 27, 2009

Oracle Client on Windows 7

Oracle sucks, but we're forced to use it at work. Of course Oracle can't get off their collective asses and put out a compatible client even after Windows 7 has, for all intents and purposes, been released. Here's a potential fix though:

http://msutic.blogspot.com/2009/08/how-to-instal-oracle-client-11g-on.html

Monday, August 24, 2009

Disable a Button (Client Side)

This code is great for when you want to make sure a person doesn't click a button more than once - but do it in a prettier way (you of course should verify everything in your code-behind as well, but this makes it pretty damn clear to your users):

StringBuilder sbValid = new StringBuilder();
sbValid.Append("if (typeof(Page_ClientValidate) == 'function') { ");
sbValid.Append("if (Page_ClientValidate() == false) { return false; }} ");
sbValid.Append("this.value = 'Please Wait...';");
sbValid.Append("this.disabled = true;");
sbValid.Append("document.forms[0].ctl00_ContentPlaceHolder1_btnPaymentSubmit.disabled = true;");
sbValid.Append(this.Page.GetPostBackEventReference(this.btnPaymentSubmit));
sbValid.Append(";");
btnPaymentSubmit.Attributes.Add("onclick", sbValid.ToString());

Thursday, August 20, 2009

Reset Scroll Position When Using MaintainScrollPositionOnPostback

If you're using MaintainScrollPositionOnPostback="true" to, well, maintain your scroll position on postback, sometimes you still want to bump the scroll up to the top (if you're using multiple panels or whatever. Here is a nice and easy fix.

1. Put this method in your code-behind:

    private void ResetScrollPosition()
{
if (!ClientScript.IsClientScriptBlockRegistered(this.GetType(), "CreateResetScrollPosition"))
{
ClientScript.RegisterClientScriptBlock(this.GetType(), "CreateResetScrollPosition", "function ResetScrollPosition() {" + Environment.NewLine +
" var scrollX = document.getElementById('__SCROLLPOSITIONX');" +
Environment.NewLine + " var scrollY = document.getElementById('__SCROLLPOSITIONY');" +
Environment.NewLine + " if (scrollX && scrollY) {" +
Environment.NewLine + " scrollX.value = 0;" +
Environment.NewLine + " scrollY.value = 0;" +
Environment.NewLine + " }" +
Environment.NewLine + "}", true);

ClientScript.RegisterStartupScript(this.GetType(), "CallResetScrollPosition", "ResetScrollPosition();", true);
}
}


2. Call ResetScrollPosition(); in any method where you want to reset the scroll position.