RSS
 

How to use ASP.NET AjaxControlToolkit

18 Dec

Follow these steps to install the AjaxControlToolkit into your Visual Studio enviroment: http://www.asp.net/ajaxlibrary/act.ashx

Here is an example of the PopupExtender control


Include:
<%@ Register Assembly=”AjaxControlToolkit” Namespace=”AjaxControlToolkit” TagPrefix=”asp” %>

Javascript function to close the pop-up:
function hideajaxpop() {
var bh = $find(“PopEx”);
bh.hidePopup();
}
ASP.NET controls to make the pop-up work:
<asp:HyperLink ID=”HyperLink1″ runat=”server” Font-Underline=”True”>Add Patient</asp:HyperLink>
<asp:Panel ID=”pnlPatientSignup” runat=”server” Style=”display: none”>
<div>
<a onclick=”hideajaxpop(); return false;” title=”Close”>X</a>
</div>
<uc3:ClinSignUpPatient ID=”ClinSignUpPatient1″ runat=”server” />
</asp:Panel>
<asp:ToolkitScriptManager ID=”ToolkitScriptManager1″ runat=”server”>
</asp:ToolkitScriptManager>
<asp:PopupControlExtender ID=”PopEx” runat=”server”
TargetControlID=”HyperLink1″
PopupControlID=”pnlPatientSignup”
Position=”Bottom” />
 
 

Determine what part of your site is actually used

26 Oct

Why put your development effort / dollars into areas of the site / web application no one is using. Or use this to question areas you are developing and verbally ask clients why they don’t use a certain portion of your site, you might find out only a small change makes all the difference in the world to your client.

Google analytics is a great tool to determine where users are going and what they’re doing on your site. On top of the typical usage on seeing which pages get hit, here is the necessary code to see which buttons get clicked or any other event on your site.

——————————————-
Place this in the <head> tag of your page (use your correct Account ID, the rest will stay the same)

<script type=”text/javascript”>
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-1111111-1']);
_gaq.push(['_setDomainName', 'none']);
_gaq.push(['_setAllowLinker', true]);
_gaq.push(['_trackPageview']);
(function () {
var ga = document.createElement(’script’); ga.type = ‘text/javascript’; ga.async = true;
ga.src = (‘https:’ == document.location.protocol ? ‘https://ssl’ : ‘http://www’) + ‘.google-analytics.com/ga.js’;
var s = document.getElementsByTagName(’script’)[0]; s.parentNode.insertBefore(ga, s);
})();
</script>

<script type=”text/javascript”>
var _gaq = _gaq || [];            _gaq.push(['_setAccount', 'UA-1145632-1']);            _gaq.push(['_setDomainName', 'none']);            _gaq.push(['_setAllowLinker', true]);            _gaq.push(['_trackPageview']);
(function () {                var ga = document.createElement(’script’); ga.type = ‘text/javascript’; ga.async = true;                ga.src = (‘https:’ == document.location.protocol ? ‘https://ssl’ : ‘http://www’) + ‘.google-analytics.com/ga.js’;                var s = document.getElementsByTagName(’script’)[0]; s.parentNode.insertBefore(ga, s);            })();
</script>

——————————————-
Place this in the hyperlink or button’s onclick event (ClickDescHere is what will show up in Google Analytics), if you have multiple subdomains like we have Google even breaks down the click events for you by hostname.

onclick=”_gaq.push(['_trackEvent', 'ClickDescHere']);”

 
 

PHP / MySQL – Upload a file to access later

01 Jun

In this example I am uploading to the file system, but saving the location in mySQL to reference later.

<form action=”insert.php” enctype=”multipart/form-data” method=”post”>
<input name=”MAX_FILE_SIZE” type=”hidden” value=”20000000″ />
<input name=”fileupload” type=”file” />
<input alt=”Submit Form”/>
</form>

————————————————————–

//Database variables are located with-in here
include(“dataconnection.php”);

$con = mysql_connect($hostname, $username, $password);
if (!$con)
{ die(‘Could not connect: ‘); }

$selected = mysql_select_db($dbname);

//Generate Random Number & date to add to file name so they’re always unique
$rNumb=rand();
$today = getdate();
$id=$today['mon'].$today['mday'].$today['year'].” “.$rNumb;
$id2=str_replace(” “,”",$id);

//Move temp file auto created to permanent location
$uploadfile = ‘uploadfiles/’ . $id2 . basename($_FILES['fileupload']['name']);
if (move_uploaded_file($_FILES['fileupload']['tmp_name'], $uploadfile)) { }
else {}

//Check to see if anything was uploaded, otherwise set variable to nothing
if($uploadfile == ‘uploadfiles/’ . $id2)
{$uploadfile = “”;}

if (!mysql_query($sql,$con))
{ die(‘There was an issue, please go back and try again, if it still happens please contact technical support’); }

mysql_close($con)
?>

 
 

PHP – handling apostrophes

01 Jun

Here is the code you’ll need to use to handle apostrophes, this just adds a backslash in front of the apostrophes

$myvariable = str_replace(“‘”,”\’”,$myvariable);

 
 

Emailing from PHP

01 Jun

about 98% of the time your web host will already have the php.ini file set up correctly so literally all it takes to email is this (if that’s not the case look here: http://www.php.net/manual/en/ref.mail.php#77499)

//Send Emails
$emailmessage = “Body of your message goes here, I put it in a variable because it’s usually very long.”;
mail($_POST[email], “Email Subject”, $emailmessage , “From: no@no.com” . “\r\n” .”bcc: lucas.baran@figers.com”);
 
 

Good looking dynamic buttons using vb.net

15 Feb

There will be no grey border, that’s just a Wordpress thing…

button.aspx
—————-

<%@ Page Language=”vb” AutoEventWireup=”true” CodeBehind=”button.aspx.vb” Inherits=”dcsui.Dynamicbutton” %>
<%@ OutputCache VaryByParam=”m;t” Duration=”9123123″ %>

<%@ Page Language=”vb” AutoEventWireup=”true” CodeBehind=”button.aspx.vb” Inherits=”dcsui.Dynamicbutton” %><%@ OutputCache VaryByParam=”m;t” Duration=”9123123″ %>

button.aspx.vb
——————–

Partial Public Class Dynamicbutton

Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

Dim text As String = Me.Request.QueryString(“t”)

If String.IsNullOrEmpty(text) Then

Throw New ApplicationException(“The text url parameter must be specified”)

End If

Dim sMirror As String = Me.Request.QueryString(“m”)

Dim mirror As Boolean = (Not String.IsNullOrEmpty(sMirror) AndAlso sMirror = “t”)

Dim rightImageWidth As Integer = 10

‘ in pixels

Dim imageHeight As Integer = 42

Dim topPadding As Integer = 11

‘ top and bottom padding in pixels

Dim sidePadding As Integer = 10

‘ side padding in pixels

Dim textBrush As System.Drawing.SolidBrush = New SolidBrush(Color.White)

Dim font As System.Drawing.Font = New Font(“Arial Black”, 11)

‘——– Calculate the text’s width

Dim bitmap As System.Drawing.Bitmap = New Bitmap(300, 300)

Dim graphics__1 As System.Drawing.Graphics = Graphics.FromImage(bitmap)

Dim textSize As System.Drawing.SizeF = graphics__1.MeasureString(text, font)

bitmap.Dispose()

graphics__1.Dispose()

‘——– Create the graphics object

Dim bitmapWidth As Integer = sidePadding * 2 + CInt(textSize.Width)

bitmap = New Bitmap(bitmapWidth, imageHeight)

‘bitmap = new Bitmap(500, 40);

graphics__1 = Graphics.FromImage(bitmap)

‘ Draw the background

Dim leftImage As System.Drawing.Image = System.Drawing.Image.FromFile(Me.Server.MapPath(“~/images/dcs/button-left.png”))

Dim rightImage As System.Drawing.Image = System.Drawing.Image.FromFile(Me.Server.MapPath(“~/images/dcs/button-right.png”))

graphics__1.DrawImage(leftImage, 0, 0, bitmapWidth – rightImageWidth, imageHeight)

graphics__1.DrawImage(rightImage, bitmapWidth – rightImageWidth, 0, rightImageWidth, imageHeight)

‘ These disposes are necessary, otherwise the files get locked

leftImage.Dispose()

rightImage.Dispose()

If mirror Then

bitmap.RotateFlip(RotateFlipType.RotateNoneFlipX)

End If

‘ Draw the text

graphics__1.DrawString(text, font, textBrush, sidePadding, topPadding)

‘——– Serve the Image

Me.Response.ContentType = “image/x-png”

Dim memStream As System.IO.MemoryStream = New System.IO.MemoryStream()

bitmap.Save(memStream, System.Drawing.Imaging.ImageFormat.Png)

memStream.WriteTo(Me.Response.OutputStream)

‘ Some cleanup, not sure if it is all needed

Me.Response.[End]()

memStream.Dispose()

graphics__1.Dispose()

bitmap.Dispose()

End Sub

End Class

———————————————————————————–
Save these two button images to the correct location as specified in the code above (use Photoshop to change the color)
 
 

Search Engine Optimization

19 Jan

Rather than re-write the topic I wanted to pass on this link which is a great beginners guide to SEO.

http://guides.seomoz.org/beginners-guide-to-search-engine-optimization

 
 

SQL findtext – create a stored proc to find text in other stored procs

19 Jan
This stored proc has come in handy many times, great to use it to find text in other stored procedures
—————————————————————–
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
CREATE   PROCEDURE [dbo].[findText] (
@text VARCHAR(50)
) AS
–Declare @text varchar(50)
–set @text  = ‘SmIepHeader’
– Adjust search text to find all contains.
SET @text = ‘%’ + @text + ‘%’
– Declare general purpose variables.
DECLARE @line VARCHAR(300)
DECLARE @char CHAR
DECLARE @lineNo INTEGER
DECLARE @counter INTEGER
– Declare cursor structure.
DECLARE @proc VARCHAR(50),
@usage VARCHAR(4000)
– Declare cursor of stored procedures.
DECLARE codeCursor CURSOR
FOR
SELECT SUBSTRING(OBJECT_NAME(id),1,50) AS sproc,
text
FROM syscomments
WHERE text LIKE @text
– Open cursor and fetch first row.
OPEN codeCursor
FETCH NEXT FROM codeCursor
INTO @proc,@usage
– Check if any stored procedures were found.
IF @@FETCH_STATUS <> 0 BEGIN
PRINT ‘Text ”’ + SUBSTRING(@text,2,LEN(@text)-2) + ”’ not found in stored procedures on database ‘ + @@SERVERNAME + ‘.’ + DB_NAME()
– Close and release code cursor.
CLOSE codeCursor
DEALLOCATE codeCursor
RETURN
END
– Display column titles.
PRINT ‘Procedure’ + CHAR(39) + ‘Line’ + CHAR(9) + ‘Reference ‘ + CHAR(13) + CHAR(13)
– Search each stored procedure within code cursor.
WHILE @@FETCH_STATUS = 0 BEGIN
SET @lineNo = 0
SET @counter = 1
– Process each line.
WHILE (@counter <> LEN(@usage)) BEGIN
SET @char = SUBSTRING(@usage,@counter,1)
– Check for line breaks.
IF (@char = CHAR(13)) BEGIN
SET @lineNo = @lineNo + 1
– Check if we found the specified text.
IF (PATINDEX(@text,@line) <> 0)
PRINT @proc + CHAR(39) + STR(@lineNo) + CHAR(9) + LTRIM(@line)
SET @line = ”
END ELSE
IF (@char <> CHAR(10))
SET @line = @line + @char
SET @counter = @counter + 1
END
FETCH NEXT FROM codeCursor
INTO @proc,@usage
END
– Close and release cursor.
CLOSE codeCursor
DEALLOCATE codeCursor
RETURN
 
 

Dynamically adding controls to a placeholder control in ASP.NET

06 Oct

Loop through your collection of controls (count of i) you would like to add to the ASP.NET placeholder control on your aspx page.

Dim lnkButtonSelfInitiate As LinkButton = New LinkButton()
lnkButtonSelfInitiate.Text = vCellLocalLink.InnerText
AddHandler lnkButtonSelfInitiate.Click, AddressOf btn_Click
Me.plhSelfInitiate.Controls.Add(lnkButtonSelfInitiate)
Protected Sub btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Me.lblTest.Text = “test”
End Sub
 
 

Launch a new window in ASP.NET on a button click using Javascript

06 Oct

The code is pretty simple, but it’s nice to have this snippet around when you need it.

Dim ReportURL as string = “http://www.figers.com”

Dim js As String = ”<script language=”"javascript”" type=”"text/javascript”"> window.open(‘” & ReportURL & “‘);</script>”

Page.ClientScript.RegisterClientScriptBlock(Me.GetType, “NewWindow”, js)