Update Panel with Update Progress

by pmcgann 8. May 2012 21:58

This is a simple example of showing a loading image while an update panel is waiting to load.

Go to this site and generate a loading image : Ajax Image Generator

Then add an update progress control to your page where the update control is and set the AssociatedUpdatePanelID to that of your update panel.

Inside the update progress add the progress template and then insert the image that you generated at the previous site.

Below is a example of this:

<asp:UpdatePanel ID="up_controls" runat="server">

            <ContentTemplate>

                <asp:PlaceHolder ID="ph_controls" runat="server"></asp:PlaceHolder> 

            </ContentTemplate>

        </asp:UpdatePanel>

        <asp:UpdateProgress AssociatedUpdatePanelID="up_controls" ID="up_progress" runat="server">

            <ProgressTemplate>

                <div class="form-content">

                    <p>

                        <img src="images/ajax-loader.gif" alt="Loading" />

                    </p>

                </div>

            </ProgressTemplate>

        </asp:UpdateProgress>

Tags:

Ajax | ASP.Net | VB.Net | Visual Studio 2008 | Tip and Tricks

Date Manipulation ASP.Net

by Gavin 11. April 2012 19:02

Tags:

ASP.Net | VB.Net

Converting text from asp.net into .csv

by Colin Graham 2. February 2012 02:08

One painful experience we have had this week has been in converting some data from one of our databases into a .csv.  This sounds simple doesn't it ??  however there were very specific requirements as the .csv had to be imported into a second system. 

We were using the stringbuiler.append method but found that the only way this would work was via the Stringbuilder.appendline method.

 

anyway hope this can help someone else out there.

 

C

Tags:

ASP.Net | VB.Net

Validate Email Host

by pmcgann 4. June 2011 09:58

It is quite easy to by-pass standard email validation something as simple as me@me.com is a valid email address. To add some extra validation we can use sockets to validate the email address host. The following function will take validate the email address hostname.

 Public Shared Function fun_ValidateEmailHost(ByVal Email As String) As Boolean

        Try
            Dim host As String() = Email.Split("@")
            Dim hostname As String = host(1)

            Dim soc As Socket
            Dim entry As IPHostEntry = Dns.GetHostEntry(hostname)
            Dim EndPoint As IPEndPoint = New IPEndPoint(entry.AddressList(0), 25)
            soc = New Socket(EndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)
            soc.Connect(EndPoint)

            Return True

        Catch ex As Exception

            Return False

        End Try


    End Function

Tags:

ASP.Net | Security | VB.Net

Download and Save Image Using URL

by pmcgann 4. April 2011 18:12

If you need to download images across sites try using this function.

Public Function getImageByUrl(ByVal url As String, ByVal filename As String) As Boolean

        Dim response As WebResponse = Nothing
        Dim remoteStream As Stream = Nothing
        Dim readStream As StreamReader = Nothing
        Try
            Dim request As WebRequest = WebRequest.Create(url)
            If request IsNot Nothing Then
                response = request.GetResponse()
                If response IsNot Nothing Then
                    remoteStream = response.GetResponseStream()

                    readStream = New StreamReader(remoteStream)

                    Dim img As System.Drawing.Image = System.Drawing.Image.FromStream(remoteStream)

                    If img Is Nothing Then
                        Return False
                    End If

                    img.Save(System.Web.HttpContext.Current.Server.MapPath("\databaseimages\") & filename, System.Drawing.Imaging.ImageFormat.Jpeg)
                    img.Dispose()
                End If
            End If
        Finally
            If response IsNot Nothing Then
                response.Close()
            End If
            If remoteStream IsNot Nothing Then
                remoteStream.Close()
            End If
            If readStream IsNot Nothing Then
                readStream.Close()
            End If
        End Try

        Return True
    End Function

Tags:

ASP.Net | VB.Net

Name 'Session' is not declared - VB.NET

by Jeremy Brown 28. January 2011 02:06

In a class you need to declare a session slightly differently:

HttpContext.Current.Session("SessionName")

Tags:

VB.Net

Export DataTable To CSV

by pmcgann 17. December 2010 22:17

A common task that developers often encounter is exporting data to a csv file. The below code takes any datatable passed into it along with a filename and exports the datatable to csv.

Public Shared Function Export_CSV(ByVal dt As DataTable, ByVal Filename As String) As String

        Dim message As String = Nothing

        Try
            Dim context As HttpContext = HttpContext.Current
            context.Response.Clear()

            For Each column As DataColumn In dt.Columns
                context.Response.Write(column.ColumnName + ",")
            Next

            context.Response.Write(Environment.NewLine)

            For Each row As DataRow In dt.Rows

                For i As Integer = 0 To dt.Columns.Count - 1
                    context.Response.Write(row(i).ToString.Replace(",", String.Empty) + ",")
                Next

                context.Response.Write(Environment.NewLine)

            Next

            context.Response.ContentType = "txt/csv"
            context.Response.AppendHeader("Content-Disposition", "attachment; filename=" + Filename + ".csv")
            context.Response.End()

            message = "Export Successful"

        Catch ex As Exception

            message = ex.Message.ToString

        End Try

        Return message

    End Function

Tags:

ASP.Net | SQL Server | VB.Net

Validation String Check For Invalid Characters

by Colin Graham 10. November 2010 23:27

sInvalidChars = "!#$%^&*()=+{}[]|\;:'/?>,< "

For iPos = 1 To Len(AddressString)

  If InStr(sInvalidChars, Mid(AddressString, iPos, 1)) > 0 Then
    IsValidEmailAddress = False
    Exit Function
  End If

Next

 

Tags:

ASP.Net | VB.Net

Calculate Age Accurately

by Colin Graham 10. November 2010 23:17

This function can be used to calculate a persons age accurately.

 

 

myAgevar = DateDiff(DateInterval.Year, CDate(dte), Now.Date) - CLng(IIf(Format(CDate(dte), "MMdd") > Format(Now.Date, "MMdd"), 1, 0))

Tags:

ASP.Net | VB.Net

Limit the number of words in a string using VB.Net

by Jeremy Brown 10. November 2010 21:54

Are you limiting the number of characters you display on the page and it's cutting words off half way through?  Try this nice little function to limit the number of words in a string.

Public Shared Function fun_LimitWord(ByVal str As String, ByVal intLimit As Integer) As String

    Dim strA() As String = str.Split(" "), strNewString As String = ""
    Dim intLength As Integer = str.Length
    Dim TChrs As Int32
    Dim i As Int32, intWordCount As Integer = 1

    If strA.Length > intLimit Then

        For i = 0 To intLimit Step +1
            If intWordCount = intLimit Then
                strNewString = Left(str, TChrs)
            End If
            TChrs += strA(i).Length + 1 '(+1 for space)
            intWordCount += 1
        Next

    Else
        strNewString = str
    End If

    Return strNewString

End Function

Tags: ,

ASP.Net | VB.Net

 

Posts By Date

Log in