Programming Journal C#, Java, SQL and to a lesser extent HTML, CSS, XML, and regex. I made this so other programmers could benefit from my experience.
Monday, May 5, 2008
Multiple PostBack problem with GridView
I noticed my SelectedIndexChanged method being called twice in IE7 when I selected a gridview row. I used solution 2 at http://www.codeproject.com/KB/aspnet/GVImageCommandButtonProb.aspx to solve the problem.
Resetting a StringBuilder
Here is how to reset a StringBuilder:
References: http://forums.asp.net/t/1193708.aspx
myStringBuilder.Remove(0, myStringBuilder.Length) also works, but why bother with that one?
myStringBuilder.Length = 0;
References: http://forums.asp.net/t/1193708.aspx
Friday, April 25, 2008
Creating a GUID from scatch
Sometimes you might want a psuedo-random string value. This can be done with:
System.Guid.NewGuid().ToString();
System.Guid.NewGuid().ToString();
Saturday, April 5, 2008
Changing the default login page for use with LoginStatus control
Sometimes it is desirable to have a different default login page. For example, a simple site where administrators login at http://foo.com/admin/Login.aspx versus the standard http:foo.com/Login.aspx. The LoginStatus control will hyperlink back to the default login page. To change this default login page, change the web.config file as follows:
Reference: http://erlend.oftedal.no/blog/?blogid=55
<authentication mode="Forms" >
<forms loginUrl="~/admin/Login.aspx"></forms>
</authentication>
Wednesday, April 2, 2008
How to trim a string in javascript
How to trim a string in javascript:
Reference: http://www.nicknettleton.com/zine/javascript/trim-a-string-in-javascript
var trimmed = str.replace(/^\s+|\s+$/g, '') ;
Reading TextBox or other Control values with javascript
Reading TextBox or other Control values with javascript.
Assume TextBox ID="txtName"
First, there are the simple examples of a standard aspx page:
references: http://www.velocityreviews.com/forums/t109803-callback-manager-masterpage.html
Assume TextBox ID="txtName"
First, there are the simple examples of a standard aspx page:
Here is the complex sample used for accessing a MasterPage's updatePanel for example:
<script type="text/javascript" languague="javascript">
function simple1() {
var txtVal = $get('<%= txtName.ClientID %>').value;
}
function simple2() {
var txtVal = $document.getElementById('<%= txtName.ClientID %>').value;
}
</script>
// In the ASPX class
private string scriptKey = "alertName";
private string script = "function alertName() { var txt = document.getElementById('[txtNameID]'); alert(txt.value); }";
// In the Page_Load event
script = script.Replace("[txtNameID]", txtName.ClientID);
ClientScript.RegisterClientScriptBlock(this.Page.GetType(), scriptKey, script, true);
references: http://www.velocityreviews.com/forums/t109803-callback-manager-masterpage.html
Friday, March 28, 2008
const and static declarations
const and static declarations cannot be declared together because they are always together when marked const.
Reference: http://blogs.msdn.com/csharpfaq/archive/2004/03/12/88416.aspx
Reference: http://blogs.msdn.com/csharpfaq/archive/2004/03/12/88416.aspx
Subscribe to:
Posts (Atom)