Full Text Index on SQL Express

On SQL Express I had to do the following to get FULLTEXT index setup. I also had to make sure there was a primary key, then I went to the design of the table and right clicked on the primary key (or any colum) and select the fulltext index, when the dialog came up on the right side I selected the columns I wanted to add, click close and I was set...

use mydatabase

exec sp_fulltext_database 'enable'
go
exec sp_fulltext_catalog 'tblMyTable', 'create'
go

Javascript clickable slideshow

I did NOT write this, I wanted a javascript slidshow to show off project screen shots and found this code and wanted to make sure I had it in my archives to search for later! Got this off: http://www.javascriptkit.com/howto/show3.shtml 

in head:

<script type="text/javascript">
<!--
//preload images
var image1=new Image()
image1.src="images/screenshot.jpg"
var image2=new Image()
image2.src="images/screenshot2.jpg"
var image3=new Image()
image3.src="images/screenshot3.jpg"
var image4=new Image()
image4.src="images/screenshot4.jpg"
//-->
</script>

In the body where you want the "images" to show up...

<a href="javascript:slidelink()">
<img src="images/screenshot.jpg" name="slide" border="0" width="492" height="354" /></a>
<script type="text/javascript">
<!--
var step=1
var whichimage=1
function slideit(){
if (!document.images)
return
document.images.slide.src=eval("image"+step+".src")
whichimage=step
if (step<4)
step++
else
step=1
setTimeout("slideit()",4000)
}
slideit()
function slidelink(){
if (whichimage==1)
window.location="page1.html"
else if (whichimage==2)
window.location="page2.html"
else if (whichimage==3)
window.location="page3.html"
else if (whichimage==4)
window.location="page4.html"
}
//-->
</script>

Javascript select ASP.NET Checkboxlist items

Ok I needed a function that would select certain CheckBoxList items of an ASP.NET CheckBoxList, so here it is, hope is helps someone else out!

if you want I use this function hightlight the item in yellow:

function uStyle(cb) {
   cb.parentNode.style.backgroundColor = cb.checked ? "yellow" : "";
   cb.parentNode.style.color = cb.checked ? "blue" : "";
}

function doCertainOnes(cbControl) {

    var chkBoxList = document.getElementById(cbControl);
    var chkBoxCount = chkBoxList.getElementsByTagName("input");

    chkBoxCount[5].checked = true;
    chkBoxCount[5].focus();    //GOING TO JUMP DOWN IN THE LIST TO THE FIRST SELECTED       
    uStyle(chkBoxCount[5]);
    chkBoxCount[6].checked = true;
    uStyle(chkBoxCount[6]);
    chkBoxCount[7].checked = true;
    uStyle(chkBoxCount[7]);

  
  for (var i = 10; i < 50; i++) {
       chkBoxCount[i].checked = true;
       uStyle(chkBoxCount[i]);
    }
}

I am selecting items (array) 5, 6, 7 and 10 through 49 in the list, now you can repeat the for loop and select different ones to. I happen to know that there will always be 100 items in the checkbox list and which ones they are... I use the "focus()" function to jump to the first item selected in the list...

Use it like this:

<a href="JavaScript:doCertainOnes('<% =CheckBoxList1.ClientID %>');">Select My Favs</a>

ASP.NET cookie auto log in

Ok it is NEVER a good idea to store a cookie on a client's machine with an ID or username and password in the cookie. Can steal the cookie. Come on, cookies are good to eat, chocolate chip cookies are my fav! Anyway, take a look at this, I think joomla does this and I don't take all the credit, but this works great:

1. Obviously a login.aspx page with a checkbox to save my login.

2. Evertime the user is logged in, either themselves or through the cookie, it deletes the old one in the table and writes a new one in the table and updates the client's cookie, or adds the cookie on the client

I call this function when the log in is successful

Public Sub doChocolateChipCookies()

        Using cooks As New dsTableAdapters.cookiesTableAdapter (I use dataset object)
            Dim q, s, t As String
            Dim expires As Date

            q = (a GUID the is stored in the user table) STORED IN THE USER TABLE
            s = (this is the current sessionID from the server I save) STORED IN THE USER TABLE
            t = RandomQIDNumber() (see function below) THIS IS NEW EACH TIME

            Dim dt As New Data.DataTable
            dt = cooks.GetDataByExpires(q)
            If dt.Rows.Count > 0 Then
                expires = dt.Rows(0)("expires")
            Else
                expires = Date.Today.AddDays(90)
            End If
            dt.Dispose()

            Response.Cookies("epauth")("epq") = q 'guid to look up user to log them in with
            Response.Cookies("epauth")("eps") = s 'series to match with token from db and cookie sent
            Response.Cookies("epauth")("ept") = t 'token to match with db and cookie
            Response.Cookies("epauth").Expires = expires

            'if the "s" does NOT match "t", someone could have stollen the cookie we will clear all cookies from the db
            'and require the user to login again...

            'remove any old cookies from db
            cooks.DeleteQuery(q, s) on every login, or cookie login, see later in this post, we delete old cookies out of the table

            'add new one
            cooks.Insert(q, s, t, expires)
        End Using
    End Sub


Public Function RandomQIDNumber() As String
        Return String.Format("{0}{1}", System.Guid.NewGuid, Now.Second)
End Function


Ok, now when the session expires because I store info in session and in a session table in SQL 08 (my sessions are stored via SQL, not cookie based) I call this function and pass in the cookie if a cookie is found

If Not Request.Cookies("epauth") Is Nothing Then
   If Not checkChocolateChipCookie(Request.Cookies("epauth")) Then
                        Session("epexp") = "y"
                        Response.Redirect("login.aspx")
    End If
End If


Public Function checkChocolateChipCookie(ByVal cookie As HttpCookie) As Boolean

        Dim cooks As New dsTableAdapters.cookiesTableAdapter
        Dim q, s, t As String
        Dim dt As New Data.DataTable
        Dim bln As Boolean

        q = cookie.Item("epq")
        s = cookie.Item("eps")
        t = cookie.Item("ept")

        dt = cooks.GetDataByAuth(q, s, t) so I have a cookie table in the db and a ds routine that gets a table by all three values
        If dt.Rows.Count > 0 Then
            'lets setup a currentuser
            Session("CurrentUser") = New objUser(q) I have an objUser class
            doChocolateChipCookies() setup a new cookie delte the old one
            bln = True
        Else
            'possible security issue, remove all
            cooks.DeleteQuery1(q)
            bln = False
        End If
        dt.Dispose()
        cooks.Dispose()
        Return bln

    End Function


Hope this helps!

WebForm_DoPostBackWithOptions vs __doPostback

Hi there guys, had an issue with WebForm_DoPostBackWithOptions vs __doPostback. WebForm_DoPostBackWithOptions started showing up on a page and not showing up on other .NET pages. It was a pain in my butt! Because WebForm_DoPostBackWithOptions wasn't working, all my linkbutton had this javascript function rendered and none of the events were firing!

So after looking around I found out that I had some panels that were hidden on the page. And in one of those panels, I have a validation control, if a validation control is "hidden" on the page (the panel's visibility is set to false and later made visible) then .NET adds WebForm_DoPostBackWithOptions to the button controls and thus does not work.

To fix this I had to change the linkbuttons that were not hidden to cause validation to false. (CauseValidation=False). Once I did that, it work! What a pain in the butt!

Webservice error on the server, but not my local box

My webservice call to, example: service1.asmx/myfunction just wasn't working on the server, but on my local box it worked great, so I had to add entries in the web config...

This needs to go between your <system.web> tags in the web.config

<webServices>
    <protocols>
        <add name="HttpGet"/>
        <add name="HttpPost"/>
    </protocols>
</webServices>

Birthday diplayed as age .NET, ASP.NET, VB.NET

I needed to display the age of of a birthday field from a database. I was so tired of coding and came across this function!

I got this from a guy named "hans" on a forum, great little function I didn't have to write!

Private Function
Age(ByVal Birthday As DateTime) As Integer
Dim
year As Integer = Today.Year - Birthday.Year
If Today.Month < Birthday.Month Or (Today.Month = Birthday.Month And Today.Day < Birthday.Day) Then
Return
year - 1
Else
Return
year
End If
End Function

VS 2008 keeps asking to replace AjaxControlToolkit.dll

I had an ANNOYING problem with Visual Studio 2008 and the AjaxControlToolkit.dll. Seemed like if I had an Update Panel on the aspx age, I would get asked if I wanted to replace the AjaxControlToolkit.dll. ANNNOYING, so I did some searching and finally did this:

1. In VS 2008 I had to right click on the toolbar and choose the option "choose items," then I sorted the the .NET Framework Components and unchecked the AjaxControlToolkit version version 3.0.1xxx and keep the 3.0.2xxx.

2. Next I went to the property page of the project and references and removed the AjaxControlToolkit reference, then I went to my aspx page and re-added the ToolKitScriptManager back to the page.

That did it!

Over 13 years of Internet experience and website marketing. Tim Maxey's Tech Blog. Set out to help the lives of others by making their programming easier. No one is the "best" programmer, every good programmer knows that, or should. Always keep learning and if you do not like it, get out of it. Do what makes you happy! My main purpose is to help youth and also anyone for that matter learn they can make a good living in technology!