Saturday, August 18, 2012

Hello friends following is a list of some important things you must know while developing an asp.net web application:



Call Javascript Function From Code Behind

Page.ClientScript.RegisterStartupScript(this.GetType(), "sometext""JavaScriptFunctionName();", true);



RunTime JavaScript
  
void Confirm(string msg)
    {
        Response.Write("Your Javascript code");
    }


Subtract two Date Objects

string time = "2012-05-01 00:00:00";
TimeSpan ts = DateTime.Now.Date.Subtract(DateTime.Parse(time).Date);




Call javascript function from code behind UpdatePanel

ScriptManager.RegisterClientScriptBlock(UpdatePanel1, UpdatePanel1.GetType(), "Success", "FunctionName();", true);



Hide/Suppress blank section in Crystal Report

  • First of all goto Section Expert And Select The Section Which You Want To Suppress Like:





  • A popup window will open now write "isnull({FieldName})" in formula editor like :






Crystal Report Numeric Field To String Formula

·         Replace (cstr({FieldName},0,''),',' ,'')

      
   Problem: Error in File CrystalReport.rpt:Access to report file denied. Another program may be using it
·         Solution: Remove The Line Below From Your Web.Config File
o    <identity impersonate="true"/>



Wednesday, August 15, 2012



I developed it using dotnet(C#) and it has a nice look n feel & a very attractive user friendly interface.
To send free sms from this application you need two things
First is - an active internet connection
Second is - YouMint user id & password (if you don't have juss signup here)
Now you are ready to send free sms directly from your desktop . . .

Advantage : -

  • No adds as in youmint website
  • Instant delivery (within 5 seconds)
  • Send sms Quickly
  • Auto-sms functionality (juss click on Auto sms button to send sms after every 12 seconds to irritate your friends ;-)
  • Sms history (You can delete)
  • Group Sms (Comma separate)
  • Contact Management (Save contacts with names)
  • Import Numbers from Excel (Just copy from excel file and paste in textbox. All mobile numbers will automatically comma separate)



If anyone wants the YouMint api code feel free to contact me : Krishan Gahlot

Below is a simple case scenario to test your query writing skills. Please put your answer in comments section...
/*
Case:
I need to store news/article information. The news can also have comments and tags. News can be submitted/posted by multiple users.
*/

According to the above scenario, I have created 5 tables and inserted some data into them :-
Use the following queries to built the database and related table:


create database demo
use demo

CREATE TABLE comments(
id int identity,
news_id bigint NOT NULL,
[user_id] bigint NOT NULL,
detail varchar(max) NOT NULL,
status bit NOT NULL default 1,
comment_date bigint NOT NULL,
PRIMARY KEY (id)
)


INSERT INTO comments(news_id, [user_id],detail, status, comment_date) VALUES(1, 2, 'nice post :)', 1, 1273431296)

INSERT INTO comments(news_id, [user_id],detail, status, comment_date) VALUES( 2, 2, 'hahaha', 1, 1273431420)

INSERT INTO comments(news_id, [user_id],detail, status, comment_date) VALUES( 3, 2, '3123123', 1, 1273431452)

INSERT INTO comments(news_id, [user_id],detail, status, comment_date) VALUES( 1, 2, 'thank You', 1, 1273431475)

INSERT INTO comments(news_id, [user_id],detail, status, comment_date) VALUES( 2, 1, 'congratulations!', 1, 1273431500)


---------------------------------------------------------------

CREATE TABLE news (
id bigint identity NOT NULL,
[user_id] bigint NOT NULL,
title varchar(max) NOT NULL,
detail varchar(max) NOT NULL,
visit int NOT NULL default '0',
status bit NOT NULL default '1',
created_date bigint NOT NULL,
PRIMARY KEY (id)
)

INSERT INTO news ([user_id], title, detail, visit, status, created_date) VALUES(1, 'Extra Content', 'fasdfasdf', 2, 1, 1273431296)

INSERT INTO news ([user_id], title, detail, visit, status, created_date) VALUES(1, 'My My Question', 'this is jpt question.. :D', 16, 1, 1273431389)

INSERT INTO news ([user_id], title, detail, visit, status, created_date) VALUES(2, 'Am I ram?', 'I am ram..yahoo !!', 3, 1, 1273431420)

----------------------------------------------------------


CREATE TABLE tags (
id bigint identity NOT NULL ,
name varchar(255) NOT NULL,
slug varchar(255) NOT NULL,
PRIMARY KEY (id)
)

INSERT INTO tags (name, slug) VALUES('sagarmatha', 'sagarmatha')
INSERT INTO tags (name, slug) VALUES('nepal', 'nepal')
INSERT INTO tags (name, slug) VALUES('gautam buddha', 'gautam-buddha')
INSERT INTO tags (name, slug) VALUES('testing', 'testing')
INSERT INTO tags (name, slug) VALUES('tags', 'tags')
INSERT INTO tags (name, slug) VALUES('tasty apple', 'tasty-apple')
INSERT INTO tags (name, slug) VALUES('banana', 'banana')

------------------------------------------------------------

CREATE TABLE tags_news (
id bigint identity NOT NULL,
news_id bigint NOT NULL,
tags_id bigint NOT NULL,
PRIMARY KEY (id)
)


INSERT INTO tags_news (news_id, tags_id) VALUES(1, 1)
INSERT INTO tags_news (news_id, tags_id) VALUES(1, 2)
INSERT INTO tags_news (news_id, tags_id) VALUES(1, 3)
INSERT INTO tags_news (news_id, tags_id) VALUES(2, 4)
INSERT INTO tags_news (news_id, tags_id) VALUES(2, 5)
INSERT INTO tags_news (news_id, tags_id) VALUES(2, 6)
INSERT INTO tags_news (news_id, tags_id) VALUES(3, 6)
INSERT INTO tags_news (news_id, tags_id) VALUES(3, 7)

-----------------------------------------------------------

CREATE TABLE users (
id bigint identity NOT NULL,
[user_id] bigint NOT NULL,
firstname varchar(100) NOT NULL,
lastname varchar(100) NOT NULL,
PRIMARY KEY (id)
)


INSERT INTO users ([user_id], firstname, lastname) VALUES(1, 'Mukesh', 'Chapagain')

INSERT INTO users ([user_id], firstname, lastname) VALUES(2, 'Christopher', 'Gayle')

INSERT INTO users ([user_id], firstname, lastname) VALUES(3, 'Brian', 'Lara')




-- Questions...

  1. SELECT NEWS WITH COMMENTS COUNT FOR EACH NEWS
  2. SELECT NEWS POSTED BY ANY PARTICULAR USER (HERE, user_id = 1)
  3. SELECT NEWS POSTED BY ANY PARTICULAR USER (WITH USER’S FIRSTNAME AND LASTNAME) (HERE, user_id = 1)
  4. SELECT NEWS POSTED BY ANY PARTICULAR USER (WITH COMMENTS COUNT FOR EACH NEWS) (HERE, user_id = 1)
  5. SELECT COMMENTS FOR ANY PARTICULAR NEWS (HERE, news_id =1)
  6. SELECT COMMENTS FOR ANY PARTICULAR NEWS (ALONG WITH USER INFORMATION) (HERE, news_id = 1)
  7. SELECT TAGS FOR ANY PARTICULAR NEWS (HERE, news_id = 1)
  8. SELECT NEWS BY TAG NAME (HERE, tag = ‘nepal’)
  9. SELECT NEWS BY TAG NAME (ALONG WITH COMMENTS COUNT) (HERE, tag = ‘nepal’) 
  10. SELECT TAG CLOUD

Hope this scenario helped you all...........


Are you a web developer or a newbie in web who wants to experiment your newly created website or a prototype and test it locally. If yes then Internet Information Service (IIS) comes to the rescue. Just like Apache, IIS would host the website for you on your computer for free without any hassle which you can access from anywhere on the internet. Follow the steps below to host your own website...

Step 1: First you have to publish your website, for that click on Build on the top menu and then click on Publish Web Site.



Step 2: Following window would open up, just click on the browse button adjacent to the address text box and set the location as given in the following screenshots.





Step 3: If there are no errors in the code and publishing is successful then output box would show something like this.

Step 4: Now your website is published, you now need to setup a web server to host it, here we’d be using Microsoft’s Internet Information Service (IIS).

Step 5: Open IIS manager and  on the left side-bar expand the tree and right-click on the Sites and then click on Add Website….

Step 6: Now give your website a name and enter the path where you published it.

Step 7: If successful the website would appear in the tree on left side-bar as shown below
Step 8: Now make sure to stop the Default Web Site or any other website which is on the same port, here our ’Hello World’ web app is at port 80.
There are two ways of doing it, either right-click on Default Web Site and via Manage Web Site submenu click on Stop, or select Default Web Site and click on Stop in the right side-bar, as shows in the screenshot.
Step 9: Now click on Edit Permissions… as the access to your website would be prohibited on default. For that first make sure Hello World website is selected from the side-bar and then click on Edit Permissions on the right side-bar.

Step 10: Go to Security tab and click on Edit button


Step 11: Now click on Add to allow more users to access this website

Step 12: Now Click on Advanced
Step 13:Now click on Find Now button and search and select Everyone and press the OK button as here in this tutorial we’d be giving access to everyone who tries to access this webpage.




Step 14: Make sure Hello World website is selected on the left side-bar and click on Start in the right side bar as shown below.
(If successfully started then the Start button would be greyed and disabled)
Step 15: Now click on Browse *.80 (http) buttons on the right side-bar.

If everything goes well you’d be seeing your website running. And now your website has been successfully hosted on your computer, and that your computer is working as a web server for your website.

To view it anytime on the computer where you have hosted it just login to http://localhost/ (Or if you have internet connectivity then just login to http://yourIPAddress/).
That's it...cheers.........

Tuesday, August 14, 2012


If you want to disable the right click option from your website just add the following JavaScript snippet in the body tag of your page:



<script type="text/javascript">    
    document.oncontextmenu=new Function("alert('You do not have permission to copy.');return false")     
</script>


A Simple way to clear all text-box fields using a single JavaScript function to avoid post backs in Asp.net


  • Just add the below code in Head tag within your .aspx page



<script type="text/javascript">
function btnclear_onclick()
{
     for(i=0; i < document.forms[0].length; i++)
     {
          if (document.forms[0][i].type == "text" || document.forms[0][i].type == "textarea")
          {
             document.forms[0][i].value="";             
          }
     }
     return false;
}
</script>

  • Now Add the following code snippet in Button's OnClientClick property

      return btnclear_onclick();