Content feed Comments Feed

The Official ASATO Site

Hi, welcome to my blog. ASP,asp.net,Health,Javascript,JQUERY

Archive for July, 2009

Creat basic-sleek-button with photoshop

Posted by admin On July - 22 - 2009

In this tutorial I am going to be teaching you how to make a sleek button using photoshop! I’ll be going through in very small steps so even the most novice user can follow along.

Step 1

First up create a new document – I’ve made sure that I have lots of room to work with so I chose 540 by 440 as my size.

Fill the background with a dark gradient or just a solid colour (Edit > Fill and use a colour like #262626) if you don’t know how.

Step 2

Create a new layer (Layer > New > Layer). Select the rounded rectangle tool and use the settings below.

Left click somewhere in the middle of your document.

Right click and left click “make selection”.

Now you should have a selection like this:

Step 3

Next up we are going to be filling our selection with a gradient. Select the gradient tool anduse these settings. You can get the green gradient by clicking that area and changing the left colour to #7ebe3e and the right to #a8da77 or by setting your foreground colour to #7ebe3e and your background colour to #a8da77 whatever suits you :)

Left click in the middle of the selection and drag to the bottom while holding the shift key (which keeps it straight) and release. Now you can deselect your selection (Ctrl + D).

Step 4

Now we are going to be adding an outside stroke to our button. The easiest way to do this is to go Layer > Layer Style > Stroke.

Step 5

On a new layer (Layer > New > Layer) make a selection of 3 by 40 pixels in the position shown below. The easiest way to do this is to select the rectangular marquee tool and use the fixed size setting with width set to 3 pixels and the height set to 40 pixels.

Fill (Edit > Fill) with white (#ffffff). And deselect (Ctrl + D if you’ve forgotten already). And with any luck your button should now be looking like this…

Step 6

Add a double arrow “»” (copy and paste it if you want) on a new text layer.

Step 7

Go Layer > Layer Style > Drop Shadow.

This should make it a little easier to read and stand out from the background a little bit – some depth.

Step 8

Add some text for your button like your website’s name or something like “Home” if it is going to be a link to the home page and you are complete.

Here is an orange version of the button. You can change the colour of the button by adding a different coloured gradient to the base layer (the first layer we created).

Prevent SQL Injection Attacks –part 1.

Posted by admin On July - 8 - 2009

What is a SQL Injection Attacks?
A SQL Injection attack is a form of attack that comes from user input that has not been checked to see that it is valid.There are two main types of attacks. First-order attacks are when the attacker receives the desired result immediately, either by direct response from the application they are interacting with or some other response mechanism, such as email. Second-order attacks are when the attacker injects some data that will reside in the database, but the payload will not be immediately activated. I will discuss each in more detail later in this article.

There is an example,here we have two form element,a textbox for user name and a password box for password.
<form action="myscript.aspx">
<input type="textbox" name="username">
<input type="password" name="password"><br/>
<input type="submit">
</form>

Then in the myscript.aspx.cs :
string sql = "SELECT * FROM Users WHERE UserName = ‘" +username.text +"’ AND Password = ‘" + password.text + "’";

In the previous code block it executes the built SQL script directly, if count is greater than one, then you know the values entered in for the user name and password were the ones matching the database.

Now with that code in the previous example, suppose someone entered the following string into your username text box:
‘ or 0=0 —
Then the sql like this:
string sql = "SELECT * FROM Users WHERE UserName = ‘nike’
or 0=0 ‘ AND Password = ‘12345678′";
The apostrophe will close the username value being sent to the SQL query, then pass another argument to the SQL query, after the last argument it then comments out the rest of the query using the "–". Since the second argument they entered into your texbox is an "or" statement, the first check on the user name doesn’t matter, and since 0 is always going to equal 0 the script will execute successfully and return a positive logon. Guess what? Your intruder now has access to your application.

Let’s take another example of SQL injection,lets do this:
‘; drop table users —
Definitely something that can ruin your day. Of course this type of an attack you’ll probably notice pretty quick.

How to preventing SQL Injection Attacks?
first: Parameterised Queries
secend:Using Stored Procedures

(to be continued)

Gossip Bombs Away

Posted by admin On July - 7 - 2009

May 19th, 2009

225blair-serena.jpg

I can barely keep my eyes open after what was an extremely busy and strenuous week. You’re welcome for all the juicy gossip I gave you. You know I had to reward my faithful readers with something for these past four loyal years. Hope I didn’t disappoint…

Graduation day was here and all our favorites were ready to pomp and circumstance and do whatever it was that graduating seniors do. It seemed like our kids were leaving Constance and St. Jude’s unlike how they arrived: quietly. That was until I decided to go out with a bang. Sorry. But I just had to do something to liven up graduation. So I came up with labels for my favorites. Don’t hate. Chuck Bass: coward. Blair Waldorf: weak. Nate Archibald: whore. Dan Humphrey: ultimate insider. Serena van der Woodsen: soon to be has been.

Serena was beyond pissed. She didn’t like the way I tagged everyone and ruined graduation. Well, sorry Miss Judgmental. She decided to take matters into her own hands and find out who was behind this amazing site. With the help of her friends, everyone came together to unmask my identity. Chuck believed I was at Serena’s post-graduation luncheon so he sent me a blast. And whose phone just happened to buzz at that exact moment? Why Jonathan’s, Eric’s beloved boyfriend. This meant Jonathan was Gossip Girl??

Nope. He wasn’t (you think I would go to Montreal for winter break? Yeah freaking right). The reason Jonathan’s phone went off was because he had hacked into my system and was receiving all my emails (not to self: change password ASAP!). Because of this, Jonathan had a whole lot of dirt on everyone. This was good for no one. Except Jenny Humphrey. The Mean Girls were set on finding a new Queen Bee to take over. If Jenny wanted the job then she had to bring them the most gossipworthy piece of unknown information. Jenny didn’t even want the gig but she also didn’t want to be the lowest on the Constance food chain. Plus, Emma Boardman (remember the girl who was like obsessed with losing her V-card last fall?) had recently moved to the city and was enrolling in Constance in September. That girl was like Penelope/Hazel/Isabel 2.0. Yuck. But thanks to Jonathan, Jenny had some really juicy info. Although, this gossip would totally destroy Blair/Chuck. What was Jenny to do?

225serenadan.jpg

Meanwhile, Blair was obsessed with the information Serena had given her re: Chuck saying he loved her. Was it an “I LOVE HER!” or an “I love her?” Blair was dying to know how Chuck enunciated it as well as see if she could make him say it again. Obviously, this was not easy. Chuck would just not do it. UGH! What the eff, Chuck? Man up!

However, it seemed like the idea of Chuck ever saying he loved Blair changed when I decided to do an air raid. Of gossip. I sent out tons of confidential info that no one had known about: Dan and Ms. Carr having sex in the costume closet. Jenny’s semi nude photoshoot. Chuck sleeping with Vanessa. Blair shoplifting. Nate turning his dad into the FBI. And most importantly, Blair and Jack Bass hooking up on New Year’s. You didn’t think I’d let you all leave for college without a huge scandal, now did you?

Everyone was livid at each other. This was not the way to find out about your BFF’s most inner and darkest secrets. Wah wah. Maybe if you all weren’t so wicked this wouldn’t have happened (but then our lives would be way boring so thank you for being so salacious!). Chuck was beyond angry at Blair. How could she do that to him? And with his uncle? Blair tried to explain. Chuck had skipped town. She was lonely. Jack was there. But anyway that was beside the point. Blair didn’t want to be weak anymore. She demanded to hear those three words from Chuck once and for all. She knew he meant it. All he had to do was repeat it. Just say it! And of course, Chuck just couldn’t do it. Maybe he was a coward. Blair was crushed. Guess she and Chuck were just destined to never be together. Worst. News. Ever.

Now that all the juicy gossip was out, Jenny didn’t have a one up on the Mean Girls. This meant she was going to have to live under the dictatorship of Emma next year. Sucks. But luckily, Blair came to her defense. In Blair’s eyes, Jenny was her queen. And this meant in the fall Jenny would rule the school. Eat it, Emma. You’re under Jenny’s reign now.

My attack only made everyone more interested in finding out my true identity. So Serena texted me to meet her at The Oak Room. Did I show my face? Of course not. But I did send out a blast to everyone to meet there. Come on, people. You all make me who I am. I couldn’t do it without you. In one way or another, you’re all Gossip Girl. But I am the Gossip Girl. Don’t ever forget that. You know you love me. And you’ll be happy to know I’m coming to college with you. See ya in fall, bitches!

natessa.jpg

One week later, Dan and Vanessa were hanging out downtown by their new school, NYU. This was how it was going to be next year (um, in a coffee shop in a less than stellar zip code? Seems like some things never change). Nate showed up in his intern clothes (sexy!). The mayor’s office was not exactly what he had in mind. He begged Vanessa to take him with her to Europe. Maybe they could still have that backpacking trip they had planned earlier in the year? And seriously, how could Vanessa say no? Nate and Vanessa’s European Adventures? So jealous! Oh, and guess who the crew bumped into at the coffee shop? A random kid named Scott who had just transferred to NYU from BU. He seemed kind of cool. And familiar. I have a feeling he might be…possibly…could be, um, Lily and Rufus’ lovechild?!? Not dead, living in NYC and going to NYU? All I can say is WOW.

Serena was getting ready to spend her summer in Europe too. Looked like she was going to have a nice summer traveling around and being free-spirited Serena. Or was she? Serena was greeted by Carter Baizen (um, yes, not a misprint). He told her he finally found what they had been looking for in Santorini a couple years ago: her father. And now it seemed that her dad was in Fiji. Whaaaat? Serena had been looking for daddy van der Woodsen? Who would have known? Serena went off to Fiji to find him. With Carter. Interesting. Very interesting.

Blair was still upset over the whole Chuck thing. And to make matters worse, it didn’t help when I reported Chuck being spotted all around Europe. Summer 2008 flashback, what? However, Blair was being strong and moving on. New school, new people, new life. But then Chuck came back to the city and found Blair walking on the street. He told her why he was really in Europe: he was in Paris to get her favorite macaroons, Berlin for her favorite stockings. And then Chuck finally said it: I love you. AHHHHHHHHHHHHHHHHHHH. What we have been waiting for all this time! TOOK YOU LONG ENOUGH, C! Blair was ecstatic. OMG Chuck loves Blair. Blair loves Chuck. We can all die happy now. Woo hoo!

But sorry to rain on your parade, Blair. What goes around comes around. You know how you were all mean and stuff to Georgina? Well, that girl doesn’t take it lying down. Stealing the wheel from Jesus, Georgina decided to take control of her life and enrolled at NYU. And guess who she requested to live with? Yep, Blair Waldorf. Meet your new roomie, B. Who’s gonna bring the mini-fridge?

Oh and BTW in old people news: Rufus and Lily made up. They are madly in love, blah blah blah and Rufus proposed! OMFG they’re getting married. Serena and Dan will finally be step-brother and sister and Jenny will soon be moving into the VDW/Bass apartment. This is a game changer, people. Can’t wait to see what happens.

What a way to end the school year. This year was bananas on bananas. I would recap it all but I am just so tired. Go back and read my old blogs to refresh your memory on what an eventful 2008-2009 it has been. Because I’ve had such a crazy year I am going to take some time off this summer to reflect. As well as get ready for next year. You know I’ll miss you. Xoxo Gossip Girl.

xo xo Gossip Girl | 171 Comments »

The End is Near

May 15th, 2009

OMG!  Can you believe we’re graduating?  After four long years it’s finally coming to an end.  No more pencils.  No more books.  No more teachers–Well, until college at least.  Goodbye, Constance.  Goodbye, St. Jude’s.  It’s been real…or rather, really drama filled.  And I know what you’re all thinking.  You’re welcome.  High school wouldn’t have been the same without yours truly.  I may not have been the nicest but I was definitely the most fun.  What would high school have been without me?  Oh wait.  I know: B-O-R-I-N-G.  But have no fear.  It ain’t over just yet.   We still have a few more days of HS left.   I can’t promise anything but I will say that I might have some salacious ammo up my sleeve.  Gotta go out with a bang, right?

xo xo Gossip Girl | 70 Comments »

Prom Dramz

May 12th, 2009

124prom.jpg

Oh prom. The night we’d been waiting for since we first stepped out of our limos and town cars and into our prestigious private schools. Some of us (ahem, Blair Waldorf) had been expecting the most perfect event of our entire academic career. So was prom 2009 perfect? Not even close. But it was monumental and oh so gossip worthy.While prom was only hours away, Serena was still locked up after getting arrested for the “stolen” bracelet. Thanks, Lily. After Lily realized Serena learned her lesson, she finally came to drop the charges and let her daughter flee the coop. Serena could not believe her mother would do this to her. What kind of mother was Lily? To not only have the police arrest her only daughter but then to have her actually locked up over night, what the hell, mom? Lily was just trying to teach her daughter some respect. Serena didn’t care. She wanted nothing to do with her mother. Serena wasn’t going anywhere. She was staying in jail and giving Lily a dose of her own medicine. Oh Serena. Looks like you were ditching a prom dress for an orange jumpsuit.

Meanwhile, Blair’s prom preparations weren’t going as planned. For a girl who had made a “prom scrapbook” before she could barely read, everything was turning disastrous. The florist lost Blair’s corsage, the limo had been already booked, the hotel room was canceled and Blair’s dress was ruined at the dry cleaners. The horror! Blair was panicking. She and Nate were supposed to have a perfect night celebrating their perfect relationship as well as the end of a perfect four years. Nate had his suspicions as to what was going on. Chuck was obviously sabotaging them! But when Nate confronted him, he denied it. How many times did Chuck have to tell him? Blair was all Nate’s. Hmm…

124chuck.jpg

Over in Brooklyn, Dan was getting ready to not go to prom. He, his sister and Vanessa were going to watch scary movies (how depressing and cliché). Their prom night sounded like it was going to be just like every other sad night in their lives. But when Dan found out Serena was still in jail he knew what he had to do. He sprung her. Dan couldn’t let Serena miss her prom. I hate to say this but: Dan Humphrey, what you did was a pretty stand up thing and I half salute you (only half bc as far as I’m concerned you’re still a narc from DUMBO).

At the prom, Blair was dealing with the Mean Girls once again (btw, Blair received a dress from Paris, presumably from her father. And this new dress was AMAZING!). The Mean Girls were trying to ruin Blair’s chance of being prom queen. They were going to stuff the box with ballots that had Nelly Yuki’s name on it. Seriously, Nelly Yuki as prom queen? No thanks. As much as I love Nelly Yuki, this is prom queen not nerd queen. When Penelope went up to announce the winner she was surprised. Nelly Yuki was not the winner. It was Blair! Oh, and Nate was prom king, duh. And who was behind it all? Chuck Bass. Yep, seemed like he knew all about Blair’s prom scrapbook and was determined to make all her dreams come true. OHMYGOD!

124blate.jpg

Even though Blair got everything she wanted she was still feeling kind of bad about something. That’s when she realized that maybe this was the end of her and Nate. Nate was her high school boyfriend. And perhaps that was all he’d ever be. But it was possible that what the two of them had was something that could never go beyond the hallways of Constance and St. Jude’s. So Blair and Nate broke up. And you know what? I kind of respect them for their mature decision.

Serena and Blair met each other outside the prom. They regaled over how they had been though so much together. They were practically sisters. Aww. Like I’ve said before no one does Besties better than Serena and Blair! They make my heart melt. Of course, Serena had to fill in Blair about what Chuck had said to her that night at the Russian Tea Room. Ahhh. Blair was finally going to know how Chuck actually felt about her!!

All the while, Rufus was still upset with Lily over having Serena arrested. But he realized that it wasn’t Serena who needed to change. It was Lily. And even after twenty years, Rufus believed she was still trying to figure out she was. This hit Lily hard. Maybe Rufus was right. Lily realized the only way to make things right was to be on better terms with her own mother. She made mistakes just like Cece had made (even though she never in a million years thought she’d be that kind of mother). Now, Lily kind of understand Cece better and she was finally able to forgive her mother for all the things that had happened in the past (ie giving baby away for adoption, paying off Rufus, etc). Sweet. And luckily, Serena was wiling to forgive Lily too. Let’s give it up for mothers and daughters uniting (what? Even Gossip Girl has a mother :p ).

Okay so now that prom’s out of the way, we have graduation coming up next. The end of senior year is way tiring. Also, I have a feeling I am going to be very busy in the upcoming week. I might be dropping some explosive info. Gossip bombs away. Xoxo Gossip Girl

xo xo Gossip Girl | 53 Comments »

Save the Last Dance

May 8th, 2009

I feel like such a slacker.  Prom is only days away and yet I’ve done absolutely zero reporting on it.  I guess that’s what happens when there’s so much other drama going on (not that I’m complaining, obvi).  Is anyone else extremely excited for what should be a night we will never forget?  You know I am.  I hear this year Constance and St. Jude’s will announce a Prom Queen and King.  Hmm…Who do you think should win?  Who do you think will win?  I know who I’m voting for.  But I’m not gonna say.  Don’t want to sway any votes.  You know how persuasive I can be.  See ya at the dance!  I’ll be the one having a ball…

xo xo Gossip Girl | 59 Comments »

Shock. Total and utter shock.

May 5th, 2009

223blairserena.jpg

Shock. Total and utter shock. Serena van der Woodsen in jail? And because her own mother had her arrested? OMFG! Could it get any crazier than that? Of course it can. This is the Upper East Side, people! Okay, okay, let’s go back to how this all started so we can totally understand what exactly went down…

Gabriel had vanished with all the money Lily, her Coop and Rufus had given him to invest. Serena could not believe this was happening. She brought that loser into everyone’s lives and because of her people had just lost serious $$. Serena decided to take it into her own hands to get the money back from Gabriel. So she did what any girl would do in order to get a guy to talk to her ASAP: Serena told Gabriel she was pregnant. And it worked. Dude called back in literally seconds. Serena met Gabriel at The Palace and told him she wasn’t knocked up. Instead, she wanted all the money he was stealing back. Gabriel told her he didn’t have it. Poppy did. It was all her scheme. Turned out, Poppy was actually a faux-calite. She snuck her way into high society and was just lucky to make friends with rich people. This meant it was Poppy they were after. Bitch was going down.

By trying to clean up thw huge mess herself, Serena was hoping to not have to tell her mom about this unfortunate incident. Lily had been treating Serena so well lately. Seemed like she was truly proud of the woman Serena was becoming. Lily even gave her a diamond bracelet that was a family heirloom (it was like way, way nice). This made Serena even more uncomfortable about having to explain the money issue. She was set on working this out all on her own. If she could just get the money back and return to everyone then all would be good. Right? Unfortunately, Dan Humphrey ruined all that. Dan overheard Serena et al. talking about Gabriel taking the money and fleeing. He was stunned. Rufus had given Gabriel Dan’s college dough. Without that money there was no way Dan was gonna go to college. So he did what any dorky and neurotic kid would do: he went straight to Lily. Ugh (go back to Brooklyn). Lily wanted to keep this totally under wraps. If word got out about them being involved, Serena’s life could be ruined. Do you know what kind of bad press this would be? Lily decided to pay back all the investors herself (it’s good to be a Bass). For Rufus, though, she was making an exception. Lily was going to pay him $5,000 a month. Seemed not only a little preferential but also a bit like charity.

And while Lily was doing that, Rufus was preparing to pop the question. Yep, he wanted to be her fifth husband. Rufus went to Eric to ask for Lily’s hand in marriage (adorable!!). Eric, of course, gave his blessing but was a little apprehensive about the way Rufus was going to propose. Lily was used to elaborate proposals (like on top of pyramids or in blimps). This was not something Rufus could give to her. But he made due and decided to do it the Humphrey way. Rufus cooked up a dinner of Lily’s favorite foods and brought her lilies. Looked like the van der Woodsens (+Chuck) and the Humphreys were officially going to be united for good.

223georgina.jpg

In order to get Poppy the crew needed to whip up the most badass plan they could think of. Luckily, Georgina was there. While she was still in love with Jesus, she was easily convinced to play the part of Sherilyn Phillips, a rich Canadian who was new to New York. The first person “Sherilyn” was to meet in the Big Apple? Why none other than Poppy Lifton (and obviously Poppy agreed to meet since she only associates with rich people). The group bugged Georgina and waited around the Russian Tea Room until Poppy started talking money. It was only a matter of time until they had Poppy right where they wanted her. And I can’t believe I’m about to say this, but: Thanks for your help, Georgina.

While everyone was waiting, some major drama went down. First off, Blair was still deciding if she wanted to move into Nate’s apartment with him. This was a huge step and one she couldn’t make properly until a major question was answered: what the hell was Chuck’s deal? If Chuck wanted her then he had to tell her that. If he didn’t then she could be free. But she couldn’t make up her mind until she knew exactly how Chuck felt. So she made him tell her. And sadly, he said it was all just a game. NOOOOO! Blair was heartbroken but at least now she could move on with her life. Serena heard the whole thing and could not believe Chuck did that. What the eff? And then he finally admitted it. The reason he told Blair that it was a game was because he actually did love her (and he really said “I LOVE HER!” AHH). Chuck just couldn’t give her what she needed. OMFG! Chuck Bass just admitted he loved Blair Waldorf! But he didn’t tell her that. GAH!

223chuck.jpg

Blair informed Nate she wasn’t going to move in with him. Not because of Chuck but just because it wasn’t right. Nate agreed. They still had issues they had to work out. Blair told him maybe their next step should be prom. Omg! Prom. I almost totally forgot about it with all this crazy action happening. But yes, Nate and Blair going to prom together is like icing on the cake to four years of high school.

Georgina had Poppy right under her thumb. Or rather, “Sherilyn” did. She offered to give money for the investment and, of course, Poppy happily accepted. Yes! It was time for the bitch to get what she deserved. Unfortunately, when the cops got to the Russian Tea Room they weren’t there for Poppy. Rather, they were there for Serena! Turned out, in order to stop Serena from turning this mess into a big deal, Lily called in the police. She said her bracelet was stolen and Serena had taken it. OMG! So while Serena was being handcuffed, Poppy was able to get out scott free. With Georgina’s bible money. Yep, Georgina had given Poppy money for bibles for the church camp (with the thought she would get it right back). OMJC!

But we all know Georgina Sparks. And while she has changed a bit no one effing crosses her. With Jesus on her side or not, Georgina was now out for Poppy’s blood. It was going to be the war of the Upper East Side bitches. This was gonna get ugly.

223nateblair.jpg

Meanwhile, over at the van der Woodsens Rufus was about to get on his knee. However, he found the paperwork re: Lily paying him $5,000 a month. What the hell was that? When he confronted Lily she told him she had to take care of it herself. He was humiliated. Lily tried to explain but he didn’t care. When Serena got arrested it only made matters worse. How could Lily lock her daughter away like that? Lily argued it was for the best. She couldn’t let this scandal get out. It would totally embarrass her. Rufus was shocked. This didn’t sound like Lily. It sounded like Cece. Was Lily becoming her? Rufus wasn’t going to be proposing to Lily. Their families weren’t going to blend. Looked like it was over. Sadness.

ACK! This was insane. Serena’s in jail! Chuck admitted he loved Blair! Nate and Blair are going to prom together! Rufus and Lily are over?! Georgina is back to her old self! This is all amazing! Just what I like to see. And prom is only a week away. Save a dance for me? Xoxo Gossip Girl

open pdf files in new window with javascript

Posted by admin On July - 7 - 2009

Opening documents such as PDFs in a new window should be automated using JavaScript for the following reasons:

  • Users will often close the web browser when a PDF is opened, mistakenly believing the document has been opened in Adobe Reader
  • The attribute historically used to open a new window, target, has been removed from the HTML 4.01 Strict specification (it’s now deprecated)
  • Opening a new window is a behaviour and should be moved to the behavioural layer11.

Using JavaScript can also be particularly useful when a website is content managed. Rather than having to rely on site editors to remember to open a link to a PDF in a new window the process is handled by a simple JavaScript function.

Registering an event

The first task is to create an event that occurs when the page has loaded. Rather than trying to execute a function call using <body onload="callfunction()"> within the HTML page we’re going to use Simon Willison’s addLoadEvent(func). This will allow us to add function calls once the page has loaded.

Type the following JavaScript into the .js file (all subsequent code should be entered before this function so the addLoadEvent is last):

function addLoadEvent(func)
{
    var oldonload = window.onload;
    if (typeof window.onload != 'function') { window.onload = func; }
    else { window.onload = function() { oldonload(); func(); } }
}
addLoadEvent(fNewPDFWindows);

The function fNewPDFWindows()

Create an empty function in your JavaScript file called fNewPDFWindows. To avoid any JavaScript errors with the script, check to see if the command getElementsByTagName is available:

function fNewPDFWindows ()
{
    if (!document.getElementsByTagName) return false;
}

The second task is to create an HTML object collection of any links within the page. The following line gets all links within the page:

var links = document.getElementsByTagName("a");

Insert this line after the check to see if getElementsByTagName object method exists as follows:

function fNewPDFWindows ()
{
    if (!document.getElementsByTagName) return false;
    var links = document.getElementsByTagName("a");
}

The next task is to loop through all of the links and check to see if we want to open any of the links in a new window. If the link is to a PDF document then we’ll open it in a new window.

Looping through the links

First create the loop that goes through all the links in the page, as follows:

function fNewPDFWindows ()
{
    if (!document.getElementsByTagName) return false;
    var links = document.getElementsByTagName("a");
    for (var eleLink=0; eleLink < links.length; eleLink ++)
    {
}
}

The indexOf method

Next we need to determine as we loop through the links whether the link is to a PDF document or not. The indexOf method is ideal for this by returning the index of the search value (the position of the search value in the string). The indexOf method requires a search value but you can also specify where to start the search from within the string (in this example we don’t need to pass the method this parameter):

So pass the indexOf method the string “.pdf” to find out if the file being linked to is a PDF document. The indexOf method returns either -1 if the string isn’t found or the index of the matching text.

function fNewPDFWindows ()
{
  if (!document.getElementsByTagName) return false;
  var links = document.getElementsByTagName("a");
  for (var eleLink=0; eleLink < links.length; eleLink ++) {
    if (links[eleLink].href.indexOf('.pdf') !== -1) { }
  }
}

onclick function

Next we need to apply an onclick event to each of the links to PDF documents, so when they’re clicked the new window is opened:

links[eleLink].onclick = function() { }

First, let’s open the new window, and give the window some parameters. The parameters we’re going to pass are as follows.

  • URL – the document we want to display in the new window
  • Specs – a comma separated list of window properties such as scrollbars etc

For a comprehensive list of windows properties take a look W3C schools DOM open method page14.

The completed function in this example is as follows. This opens the link address in a new, re sizable window with scrollbars:

links[eleLink].onclick = function() { window.open(this.href,'resizable,scrollbars'); return false; }

Insert the onclick event within the if statement that detects whether a PDF document has been found:

function fNewPDFWindows ()
{
  if (!document.getElementsByTagName) return false;
  var links = document.getElementsByTagName("a");
  for (var eleLink=0; eleLink < links.length; eleLink ++) {
  if (links[eleLink].href.indexOf('.pdf') !== -1)
  { links[eleLink].onclick = function()
  {
window.open(this.href,'resizable,scrollbars');
  return false;
  }
  }
  }
}

Warning users the document opens in a a new window

The final task is to ensure users are aware that the link will open in a new window. We need to be as clear as we can with this to minimise confusion.

We’re going to do this by firstly amending the title text of the link and secondly inserting an image with alternate text of “(opens in a new window)”. The link title can be set as follows:

links[eleLink].title += "\n(opens in a new window)";

Next we will create an image element and set it’s src and alt attributes. Finally we’ll append the image to the hyperlink using the appendChild method.

var img = document.createElement("img"); img.setAttribute("src", "i/new-win-icon.gif"); img.setAttribute("alt", "(opens in a new window)"); links[eleLink].appendChild(img);

The final function is as follows:

function fNewPDFWindows ()
{
  if (!document.getElementsByTagName) return false;
  var links = document.getElementsByTagName("a");
  for (var eleLink=0; eleLink < links.length; eleLink ++) {
  if (links[eleLink].href.indexOf('.pdf') !== -1)
  { links[eleLink].onclick = function()
  { window.open(this.href,'resizable,scrollbars');
  return false;
  }
  var img = document.createElement("img");
  img.setAttribute("src", "i/new-win-icon.gif");
  img.setAttribute("alt", "(opens in a new window)");
  links[eleLink].appendChild(img);
  }
  }
}

Conclusion

This very short function demonstrates how easy it is to open links in new windows automatically. This means your site will be more likely to validate, more likely to work correctly in future browsers and will be more usable for its users.

Resources for the new window tutorial

Download the required resources before beginning this tutorial.

Start by opening the file ‘pdf-new-window.htm’. This is the content we’re going to apply our JavaScript new window function to.

Introduction
Stored procedures are T-SQL statements that are stored in the SQL Server. They are executed by calling their names, as in our case, from ASP.NET pages. They add more efficiency and compactness to the code. Imagine what it’d cost in terms of server performance if we were to send with every request to the SQL Server, a set of 5-10 T-SQL statements, which the SQL Server would have to parse and compile and then execute. This will be performance heavy. Now, compare this with the performance of a pre-compiled set of high performance code that is kept on the SQL Server and executed by just calling its name. This gives tremendous performance advantages, plus also allows one to keep lengthy bits of code compactly and in a more organized way, on the SQL Server.

In this tutorial, we will learn how to create stored procedures for four of the most common SQL tasks that every ASP.NET and database developer has to go through. And that is creating, retrieving (displaying), updating and deleting records in a table in the database. For the purpose of demonstration, we’ll first create a table, and then add four stored procedures to the database, one for each of the SQL tasks we talked of above. Let us now proceed to the code.

Creating the Table
We’ll create a table with the name of ‘Names’ in our SQL Server database. Open SQL Server Query Analyzer and copy/paste following code in it. Then press F5 key to execute/create the table.

CREATE TABLE [dbo].[Names] (
	[ID] [int] IDENTITY (1, 1) NOT NULL ,
	[FirstName] [varchar] (50) NOT NULL ,
	[LastName] [varchar] (50) NOT NULL
) ON [PRIMARY]
GO

Executing the above SQL code will create a table ‘Names’ with following structure in your SQL Server database:

Structure of Names Table

Explanation

We basically create a very simple table with just 3 columns. The first column with the name of ‘ID’ is an identity column, meaning it will increment automatically. It is also our primary key. The second and third columns with the names of ‘FirstName’ and ‘LastName’ are for storing first and last names that we’ll add later on, using ASP.NET pages.

Creating the Stored Procedures

Let us now create the four stored procedures to create, retrieve, update and delete records in the ‘Names’ table.

i. Stored Procedure for Creating a New Name

This stored procedure encapsulates the INSERT SQL statement to add a new record to the ‘Names’ table. Copy following code and paste in it your SQL Server Query Analyzer window and then press the F5 key to execute/create this stored procedure:

CREATE PROC dbo.AddName
	@FirstName	varchar(50),
	@LastName	varchar(50),
	@ID		int	OUT
AS
	INSERT INTO Names(FirstName, LastName) VALUES (@FirstName, @LastName)

	SET @ID = @@IDENTITY
GO

Explanation

After the CREATE PROC statement, comes the name of our stored procedure. We append dbo. before it to tell SQL Server that this stored procedure belongs to ‘dbo’ user account. We then tell SQL Server that this stored procedure will be accepting three arguments of the type given above. The third argument has the keyword OUT appended to it, which tells SQL Server that we’ll be using this argument to send data back to the calling ASP.NET page. Finally, after the INSERT statement, we retrieve the primary key of the newly added record using SQL Server’s @@IDENTITY variable. We assign it’s value to the out-going ‘ID’ parameter and we are done.

Tip: Unless you really know what you are doing, always append ‘dbo.’ before the name of all the objects (tables, stored procedures) you create in SQL Server.

In a nutshell, this stored procedure will accept first and last names. It will insert them in the ‘Names’ table and return the newly generated identity back to the ASP.NET page.

ii. Stored Procedure for Retrieving All Names from the ‘Names’ Table

This stored procedure will return all the records from the ‘Names’ table. Copy following code and paste in it your SQL Server Query Analyzer window and then press the F5 key to execute/create this stored procedure:

CREATE PROC dbo.GetAllNames
AS
	SELECT [ID], FirstName, LastName FROM Names ORDER BY [ID] ASC

GO

Explanation

This stored procedure simply runs a SELECT statement to return the ID, first name and last name of all the names added to the ‘Names’ table. Executing this stored procedure, which does not accept any argument, will display a list of all names in the ‘Names’ table.

iii. Stored Procedure for Updating a Given Name

This stored procedure will update the first and last names of a name in the ‘Names’ table using its ‘ID’. Copy following code and paste in it your SQL Server Query Analyzer window and then press the F5 key to execute/create this stored procedure:

CREATE PROC dbo.UpdateName
	@ID	int,
	@FirstName	varchar(50),
	@LastName	varchar(50)
AS
	UPDATE Names SET FirstName = @FirstName,
	LastName = @LastName WHERE [ID] = @ID

GO

Explanation

It takes three arguments to update the record using an UPDATE SQL statement. The code is straightforward.

iv. Stored Procedure for Removing a Name From ‘Names’ Table

This stored procedure will remove a given name using its ‘ID’ from the ‘Names’ table. Copy following code and paste in it your SQL Server Query Analyzer window and then press the F5 key to execute/create this stored procedure:

CREATE PROC dbo.RemoveName
	@ID	int
AS
	DELETE Names WHERE [ID] = @ID
GO

Explanation

Another very simple stored procedure. Here we use a single-line DELETE SQL statement to remove a record from the ‘Names’ table using the argument.

Assuming that you were successful in creating the ‘Names’ table and four stored procedures in your SQL Server database, we’ll move forward to create 4 ASP.NET pages similar to the 4 stored procedures.

Creating the ASP.NET front-end

Guys, let us now create the ASP.NET front-end.

i. Web.config

Since our ASP.NET will be connecting to the database, add the following connection string in your web.config file between the <connectionStrings></connectionStrings> tags:

<add name="NamesDB" connectionString="server=.;database=;user id=;password="
		  providerName="System.Data.SqlClient"/>

Add the correct server, database, username and password to be able to connect to your SQL Server database.

ii. Create.aspx

Create a new ASP.NET page and copy/paste following code in it:

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<script runat="server">
public void AddName(object obj, EventArgs args)
{
	string connStr = ConfigurationManager.ConnectionStrings["NamesDB"]
		.ConnectionString;

	using (SqlConnection con = new SqlConnection(connStr))
	using (SqlCommand cmd = new SqlCommand("AddName", con))
	{
		cmd.CommandType = CommandType.StoredProcedure;
		cmd.Parameters.Add("FirstName", SqlDbType.VarChar, 50).Value =
			FirstName.Text;
		cmd.Parameters.Add("LastName", SqlDbType.VarChar, 50).Value =
			LastName.Text;
		cmd.Parameters.Add("ID", SqlDbType.Int);

		cmd.Parameters["ID"].Direction = ParameterDirection.Output;

		con.Open();
		cmd.ExecuteNonQuery();

		Result.Text = "New record created. (" +
			cmd.Parameters["ID"].Value + ")";
		}
	}
</script>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Add a New Name</title>
    <style>
		body { font-family: Verdana; }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
	<span style="font-size: larger">Add a New Name</span><br /><br />

	First Name: <asp:TextBox ID="FirstName" runat="server" /><br />
	Last Name: <asp:TextBox ID="LastName" runat="server" /><br /><br />
	<asp:Button ID="SubmitButton" Text="Add Name"
		OnClick="AddName" runat="server" />
	</div>

	<br />
	<asp:Label ID="Result" runat="server" />
    </form>
</body>
</html>

Create.aspx

Explanation

This ASP.NET displays a form to the user. The user then enters the desired first and last names, and presses the submit button, the ASP.NET pages connects to the SQL Server and executes the ‘AddName’ stored procedure we create above to add a new record in the ‘Names’ table.

string connStr = ConfigurationManager.ConnectionStrings["NamesDB"]
	.ConnectionString;

We first retrieve the connection string in a local variable.

	using (SqlConnection con = new SqlConnection(connStr))
	using (SqlCommand cmd = new SqlCommand("AddName", con))
	{
		...
	}

Then we create connection and command objects for this connection. The command object contains the name of the stored procedure we want to execute.

	cmd.CommandType = CommandType.StoredProcedure;

We set the CommandType property of command object to be of type CommandType.StoredProcedure.

	cmd.Parameters.Add("FirstName", SqlDbType.VarChar, 50).Value =
		FirstName.Text;
	cmd.Parameters.Add("LastName", SqlDbType.VarChar, 50).Value =
		LastName.Text;
	cmd.Parameters.Add("ID", SqlDbType.Int);

	cmd.Parameters["ID"].Direction = ParameterDirection.Output;

Add three parameters to this stored procedure and setting the last parameter to receive the data set by the stored procedure, which in our case will be the ‘ID’ of the newly created record.

	con.Open();
	cmd.ExecuteNonQuery();

We then open the connection and execute the stored procedure.

	Result.Text = "New record created. (" +
		cmd.Parameters["ID"].Value + ")";

Finally, we display the retrieved id to the user. Pretty simple stuff.

iii. Retrieve.aspx

Create a new ASP.NET page and copy/paste following code in it:

<%@ Page Language="C#" %>

<script runat="server">
	public void Page_Load(object obj, EventArgs args)
	{
		GridView1.DataSource = SqlDataSource1;
		GridView1.DataBind();
	}
</script>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Retrieve All Names</title>
    <style>
		body { font-family: Verdana; }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
	<asp:SqlDataSource ID="SqlDataSource1" SelectCommand="GetAllNames"
	SelectCommandType="StoredProcedure" ProviderName="System.Data.SqlClient"
	ConnectionString="<%$ ConnectionStrings:NamesDB %>"
		runat="server"></asp:SqlDataSource>

	<asp:GridView ID="GridView1" runat="server">
	</asp:GridView>
	</div>
    </form>
</body>
</html>

Retrieve.aspx

Explanation

We use <asp:SqlDataSource> and <asp:GridView> server tags to display the result of executing the ‘GetAllNames’ stored procedure to the user.

iv. Update.aspx

Create a new ASP.NET page and copy/paste following code in it:

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<script runat="server">
public void UpdateName(object obj, EventArgs args)
{
	string connStr = ConfigurationManager.ConnectionStrings["NamesDB"]
		.ConnectionString;

	using (SqlConnection con = new SqlConnection(connStr))
	using (SqlCommand cmd = new SqlCommand("UpdateName", con))
	{
		cmd.CommandType = CommandType.StoredProcedure;
		cmd.Parameters.Add("ID", SqlDbType.Int).Value = ID.Text;
		cmd.Parameters.Add("FirstName", SqlDbType.VarChar, 50).Value =
			FirstName.Text;
		cmd.Parameters.Add("LastName", SqlDbType.VarChar, 50).Value =
			LastName.Text;

		con.Open();
		cmd.ExecuteNonQuery();

		Result.Text = "Record updated";
	}
}
</script>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Update a Name</title>
    <style>
		body { font-family: Verdana; }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
	<span style="font-size: larger">Update an Existing Name</span><br /><br />

	ID: <asp:TextBox ID="ID" runat="server" /><br />
	First Name: <asp:TextBox ID="FirstName" runat="server" /><br />
	Last Name: <asp:TextBox ID="LastName" runat="server" /><br /><br />
	<asp:Button ID="SubmitButton" Text="Update Name"
		OnClick="UpdateName" runat="server" />
	</div>

	<br />
	<asp:Label ID="Result" runat="server" />
    </form>
</body>
</html>

Update.aspx

Explanation

Presents a form, asking for a given record’s ‘ID’ whose first and last names you want to change. You supply all the arguments and click the submit button, this will execute the ‘UpdateName’ stored procedure and the first and last names corresponding to that ‘ID’ will be updated.

iv. Delete.aspx

Create a new ASP.NET page and copy/paste following code in it:

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<script runat="server">
public void DeleteName(object obj, EventArgs args)
{
	string connStr = ConfigurationManager.ConnectionStrings["NamesDB"]
		.ConnectionString;

	using (SqlConnection con = new SqlConnection(connStr))
	using (SqlCommand cmd = new SqlCommand("RemoveName", con))
	{
		cmd.CommandType = CommandType.StoredProcedure;
		cmd.Parameters.Add("ID", SqlDbType.Int).Value = ID.Text;

		con.Open();
		cmd.ExecuteNonQuery();

		Result.Text = "Record deleted";
	}
}
</script>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Delete a Name</title>
    <style>
		body { font-family: Verdana; }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
	<span style="font-size: larger">Delete an Existing Name</span><br /><br />

	ID: <asp:TextBox ID="ID" runat="server" /><br /><br />
	<asp:Button ID="SubmitButton" Text="Delete Name"
		OnClick="DeleteName" runat="server" />
	</div>

	<br />
	<asp:Label ID="Result" runat="server" />
    </form>
</body>
</html>

Delete.aspx

Explanation

Presents a form with a single input field. You enter the value of the ‘ID’ of the record you want deleted. Pressing the submit button executes the ‘RemoveName’ stored procedure which deletes the given record.

v. index.html

This page will allow you to link to all four ASP.NET pages from a single page. This way you can go to one ASP.NET page to add a new record, and come back to go to another ASP.NET page to view it. Create a new HTML page and copy/paste following code in it:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Index</title>
    <style>
    body { font-family: Verdana; }
    </style>
</head>
<body>

<div>Basic Stored Procedure Operations</div>

<ul>
<li><a href="create.aspx">Create</a></li>
<li><a href="retrieve.aspx">Retrieve</a></li>
<li><a href="update.aspx">Update</a></li>
<li><a href="delete.aspx">Delete</a></li>
</ul>

</body>
</html>

Conclusion

In this tutorial we learned about stored procedures. We learned how to create 4 basic types of stored procedures, and viewed their operations on a sample table. We also created 4 ASP.NET pages and learned how to assign parameters to stored procedures from ASP.NET pages, receive data (via OUT statement) from the stored procedure, and execute stored procedures from ASP.NET pages.

Guys, this is it. Go play with the code. Create the drop stored procedures as many times as you want. You can download all the code discussed in this tutorial from a link below. Have fun!

how to read XML file with asp?

Posted by admin On July - 1 - 2009

in this article,we will study how to reading xml file with asp.

first: what is xml file ?

XML is tag based just like HTML. there is a example:
<?xml version=”1.0″?>
<boot>
<name>Faisal Khan</name>
<name></name>
<name/>
<name language=”US-EN”>Faisal Khan</name>
</boot>

second: we save the xml file named “aspreadxml.xml”, and we will reading this xml with asp. we can get the xml document elements and attributes.
the code like this:

?View Code CSHARP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?xml version="1.0"?>
<%
dim xml,objNode,objAtr,nCntChd,nCntAtr
Set xml=Server.CreateObject("Microsoft.XMLDOM")
xml.Async=False
xml.Load(Server.MapPath("aspreadxml.xml"))
Set objNode=xml.documentElement
nCntChd=objNode.ChildNodes.length-1
for i=0 to nCntChd
set objAtr=objNode.ChildNodes.item(i)
nCntAtr=objAtr.Attributes.length-1
for j=0 to nCntAtr
response.write objAtr.Attributes.item(j).Text&"<br>"
next
response.write "<br>"
next
Set objAtr=Nothing
Set objNode=Nothing
Set xml=Nothing
%>