vijay

welcome Netizen

Share Your Knowledge.It is a way to achieve immortality

Wednesday, February 23, 2011

Search a Items in Array() String without using any Loop


Introduction:

hi..
i got an requirement to search a value in an array,Normally i knew the concept of using for loop ,we can serach the items in array,but now i found new method without using any loop ,Its easy to find a items in arrray.


Description:
                    For an examble in an array it contains more than 50 items in array,Now our requirement is search one item in that array list,Normally we use for loop,But considering the time factor we can use another method to follow to find.....

Examble:  item(0)="people"
item(1)="chair"
'
'
item(10)="raj"
In that item of array list contains 10 value from that value we are going to find the value of "raj"
Code:
Dim lst as list(of string)
lst.addrange(item)
Dim result as string =lst.contains("raj")

The result has return a boolean value,if the result has True-"it array contains that value" otherwise it return "false"

i hope this one useful to you.....

Tuesday, February 22, 2011

GOOGLE OFFER SMS CHANNEL FOR ALL USERS...


Hi..

Its  Really very intresting google has been providing  so many features for the user...Now they offers sms channel
to subscribe any channels as you like,By the way subscption you can easily get daily sms from the channels,
Also for bloggers can easily update the BLOGs articles by using sms,also  you can invites users to view your blog through sms

For that you can subscibe your blog with google sms channels get your own sms channel links..

Here is the link for subcribe for my Blog Post....

http://labs.google.co.in/smschannels/subscribe/VBDOTNETCHANNELS

click this link and join in this channel ,you can get blog updates  through sms on your mobile

also if you want to create new channel click this below link...

http://labs.google.co.in/smschannels/channel

i hope this one helpful to you..also post your valuable comments

How to Refersh a web page at a particular time Without using any script..


hi..
Introduction:
Here I will explain how to refresh a web page without using any script..
i hope this one will help for the  developer to develop a web page by using simple code.

Description:

You have to add this code in that design page, inside the Head tag..

Code:
For refresh the whole page you can use meta tag..
<head>
<meta http-equiv="refresh" content="60"/>
</head>
Here content shows the time duration for refresh the page...

i hope this one helpful to you ....

Monday, February 21, 2011

How to Disable Back Button in asp.net Web page?


hi..
i knew many of them could tried to disable the option of Back Button,Because if you would not disable the
user can easily go back to previous page ,so avoid this situation we can use javascript to diable the option
You can add this code in that header tag..Follow this steps


<head runat="server">
    <title>Untitled Page</title>
    <script language="javascript " type ="text/javascript" >
    window .history.forward();
       
    </script>
</head>

i hope this helpful to u .....

Wednesday, February 16, 2011

How to rotate the ads without refreshing the page by using Adrotator in Ajax....


hi ..Create your own add in your webpage..
In this article i describe about ,how to display the ads in webpage by using adrotator,
By using AJAX without refreshing the whole page you can easily display the diffrent ads in the particular area....
Intially the ads are stored in xml file ..
First you have to create the xml file for ads.

<Advertisements>
<Ad1>
<ImageUrl>~/images/color.jpg</ImageUrl>
<NavigateUrl>http://www.google.com</NavigateUrl>
<AlternateText>This is Sample image</AlternateText>
<Impressions>40</Impressions>
<Keyword>small</Keyword>
<width>300</width>
<Height>50</Height>
</Ad1>
<Ad2>
<ImageUrl>~/images/sample1.jpg</ImageUrl>
<NavigateUrl>http://www.yahoo.com</NavigateUrl>
<AlternateText>This is Sample image</AlternateText>
<Impressions>40</Impressions>
<Keyword>small</Keyword>
<width>300</width>
<Height>50</Height>
</Ad2>
</Advertisements>

and save it advertisement.xml

Next create an new applications

In this adrotator->>you can finthis one in toolbox
Add Script Manage and timer
and add update panel
In this adrotator properties you can add the advertisement xml file
And also  set the time for rotating the ad in the timer control

Your code should be like this....

 <asp:scriptmanager ID="Scriptmanager1" runat="server"></asp:scriptmanager>
    
    <asp:Timer ID="Timer1" Interval="2000" runat="Server">
</asp:Timer>
<asp:UpdatePanel ID="updatepanel1" runat="Server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" Eventname="Tick" />
</Triggers>
<ContentTemplate>


    <asp:AdRotator ID="AdRotator2" runat="server" DataSourceID="XmlDataSource2" />
    <asp:XmlDataSource ID="XmlDataSource2" runat="server" DataFile="~/Advertisements.xml">
    </asp:XmlDataSource>
 </ContentTemplate>
</asp:UpdatePanel>

Your add should be like this ..........

How to insert XML data into SQL Database...


hi..

Here i can simply explain to store xml data into sql database ,

create a SQL database like this...
1)carsid           varchar(50)
2)carsmodel     varchar(50)
3)carscolor       varchar(50)

This is a xml file to store into sql table..

- <system>
- <message>
  <Carsid>1</Carsid>
  <Carsmodel>Toyota</Carsmodel>
  <Carscolor>Green</Carscolor>
  </message>
- <message>
  <Carsid>2</Carsid>
  <Carsmodel>Kia</Carsmodel>
  <Carscolor>Yellow</Carscolor>
  </message>
- <message>
  <Carsid>3</Carsid>
  <Carsmodel>swift</Carsmodel>
  <Carscolor>silver</Carscolor>
  </message>
  </system>

Then enter the code behind submit button to store xml data into sql databse..

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
       
Dim Carsid, Carsmodel, Carscolor,str As String


 Dim sXMLFilePath As String = "C:\users\admin\desktop\12.xml"


        Dim document As New XmlDocument()
        document.Load(sXMLFilePath)




        Dim xmlNodeList As XmlNodeList = document.SelectNodes("system/message")
        For Each node As XmlNode In xmlNodeList
            Carsid = Integer.Parse(node("Carsid").InnerText)
            Carsmodel = node("Carsmodel").InnerText
            Carscolor = node("Carscolor").InnerText


            str = "INSERT INTO car (Carsid,Carsmodel,Carscolor) values ('" & Carsid & "', '" & Carsmodel & "','" & Carscolor & "')"
            sqlcmd = New SqlCommand(str, sqlcon)
                    sqlcmd.CommandType = CommandType.Text
                    sqlcmd.ExecuteNonQuery()
        Next




    End Sub

i hope this helpful to u.................


Sunday, February 6, 2011

Upload a Image or File into Database in ASP.NET using VB coding



hi...

In previous articles we have seen about uploading files into folder..This articles to update a files into  database...
For that you have to add following items in design side..
1) File upload
2)1 Button
3) text box
4) Label


Before in SQL you have to create a table like this..
GO
CREATE TABLE [dbo].[upload](
[fileid] [int] IDENTITY(1,1) NOT NULL,
[ImageName] [varchar](max) COLLATE SQL_Latin1_General_CP1_CS_AS NULL,
[Image] [image] NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]


Follow the server side coding....
In submit button you have to add the following codes.....

In vb.net file uploading has one important property  HTTPPOSTEDFILE, by using this property we can easily get the file upload details
like file length,file content type and file name.....Also we can easily check  file extension..For an example if we want to upload only gif image
means by using content type we can check the file type...After checking we can upload the file into database


 Try
'Checking the file in fileupload
            If FileUpload1.HasFile Then


                Dim imageSize As Byte()
                imageSize = New Byte(FileUpload1.PostedFile.ContentLength - 1) {}




                Dim postfile As HttpPostedFile = FileUpload1.PostedFile()


                postfile.InputStream.Read(imageSize, 0, CInt(FileUpload1.PostedFile.ContentLength))


                ' Create SQL Connection 
                Dim con As New SqlConnection()
                con.ConnectionString = ConfigurationManager.ConnectionStrings("Con").ConnectionString


                ' Create SQL Command 
'Checking file type
                If postfile.ContentType.ToLower() = "image/gif" Then


                    Dim cmd As New SqlCommand()
                    cmd.CommandText = "INSERT INTO upload(ImageName,Image) VALUES (@ImageName,@Image)"
                    cmd.CommandType = CommandType.Text
                    cmd.Connection = con
                    Dim ImageName As New SqlParameter("@ImageName", SqlDbType.VarChar, 50)
                    ImageName.Value = TextBox1.Text.ToString
                    cmd.Parameters.Add(ImageName)


                    Dim imagelenth As New SqlParameter("@Image", SqlDbType.Image, imageSize.Length)
                    imagelenth.Value = imageSize
                    cmd.Parameters.Add(imagelenth)
                    con.Open()
                    Dim result As Integer = cmd.ExecuteNonQuery()
                    con.Close()
                Else
                    Label1.Text = "Its not a gif image"
                End If
            Else
                Label1.Text = "please select the file to uplaod"
            End If
        Catch ex As Exception
            Response.Write(ex.Message)
        End Try


    End Sub

Hope this helps to u.....

Friday, February 4, 2011

Upload a File in ASP.NET using VB coding



hi..
In this article you are going to see about to upload file in asp.net

Folloe the client side coding......
DESIGN SIDE

Normally if you want to upload a file you have to add FILEUPLOAD its present in the toolbox

then you have to add one button rename it submit
Follow server side
SERVER SIDE:

In server side you have to add the following code in the submit button event ....

Protected Sub submit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles 

 Try

            Dim filetype As String
            Dim file As String
            Dim filepath As String
            Dim uploadpath As String
          
            file = FileUpload1.PostedFile.FileName

            filepath = Path.GetFileName(file)
            uploadpath = "d:\vijay\"

                FileUpload1.PostedFile.SaveAs(Path.Combine(uploadpath, file))
                Response.Write("upload succesfully")
           
            

        Catch ex As Exception
            Response.Write(ex.Message)


        End Try
End Sub

Normally when upload one issue araise ,How to check the upload file name extension..this one was the big problem for developer....
For checking extension in VB present one function i.e CONTENT TYPE....
By using this function you have check the file extension coding..

In this exanble i checked the gif image file ...


Try

            Dim filetype As String
            Dim file As String
            Dim filepath As String
            Dim uploadpath As String
            filetype = FileUpload1.PostedFile.ContentType
            file = FileUpload1.PostedFile.FileName

            filepath = Path.GetFileName(file)
            uploadpath = "d:\vijay\"
            If filetype = "image/gif" Then

                FileUpload1.PostedFile.SaveAs(Path.Combine(uploadpath, file))
                Response.Write("upload succesfully")
            Else
                Response.Write("its not gif file")
            End If

        Catch ex As Exception
            Response.Write(ex.Message)


        End Try
By using this method you can easily check file type at the time of upload.....

i hope this article helpful to uu.....

plz post your valuable comments here..............

Thursday, February 3, 2011

Default Button in ASP.net


hi..i have seen many of them dont know the usage of setting default button..

By reading this one you can get clear idea about uses of setting Default Button..
In an webpage when creatiing form like an application or any fill up form ,when the user enter the
field in textbox after fill up user hit the enter button on the keyboard Then the deafult button will fire..
let me see where to write default button coding ...

<form id="form1" runat="server" defaultbutton ="button3">


In the main form id you have to add the default button id...

Tuesday, February 1, 2011

GRID VIEW LOAD AND UPDATE SQL DATA TABLE INTO GRID VIEW USING ASP.NET




hi friends..

Here i describe the methods to load sql data table into grid view.By using this article you will get clear idea to load the table into grid view also you can also update the table using grid view..


--------This are Grid view coding are comes under client side ...........
[CODE]
 <asp:GridView ID="GridView1" runat="server"
            CellPadding="3" GridLines="Vertical"
            AutoGenerateColumns="False" Height="155px" Width="573px" BackColor="White"
                BorderColor="#999999" BorderStyle="None" BorderWidth="1px"
                AllowPaging="True" DataKeyNames="Number">
                    <Columns >
        <asp:TemplateField HeaderText ="PHONE NUMBER">
                        <ItemTemplate >
                        <%#Eval("Number")%>
                        </ItemTemplate>
        </asp:TemplateField>
      
        <asp:TemplateField HeaderText ="NAME" >
                        <ItemTemplate >
                         <%#Eval("Name")%>
                         </ItemTemplate>
                         <EditItemTemplate >
                         <cc1:textbox ID="txtrwname" runat="server" Text ='<%#Bind("Name")%>'></cc1:textbox>
                             </EditItemTemplate>
                </asp:TemplateField>
      
        <asp:TemplateField  HeaderText ="ADDRESS">
                        <ItemTemplate >
                        <%#Eval("Address")%>      
                        </ItemTemplate>
                        <ItemStyle HorizontalAlign="Left" />    
                           <EditItemTemplate >
                            <cc1:textbox ID="txtrwaddress" runat="server" Text='<%#bind("Address")%> ' Validate ="IsAlphaNum" ></cc1:textbox>
                            </EditItemTemplate>  
                </asp:TemplateField>
        <asp:TemplateField HeaderTEXT="CITY" >
                        <ItemTemplate >
                        <%#Eval("City")%>
                        </ItemTemplate>      
                           <EditItemTemplate>
                               <cc1:textbox ID="txtrwcity" runat="server" Text='<%#bind("City")%>'></cc1:textbox>
                                </EditItemTemplate>  
                </asp:TemplateField>
            <asp:TemplateField HeaderText ="STATE">
                        <ItemTemplate>
                         <%#Eval("State")%>
                        </ItemTemplate>
                          <EditItemTemplate>
                           <cc1:textbox ID="txtrwstate" runat="server" Text='<%#bind("State")%> ' Validate ="IsAlphaNum ">
                                    <cc1:textbox>
                                      </EditItemTemplate>
    </asp:TemplateField>
[/CODE]
---------This field are used to modify and update the database---------------------


  <asp:CommandField HeaderText ="modify" ShowDeleteButton ="false" ShowEditButton ="true" EditText ="modify" />
       <asp:TemplateField HeaderText="Delete">
                                    <ItemTemplate>
                                        <asp:LinkButton ID="lnkDelete" CommandName="Delete" runat="server" OnClientClick ="return confirm('are you sure')">Delete</asp:LinkButton>
                                    </ItemTemplate>
                                </asp:TemplateField>
  </Columns>  
 </asp:GridView>

---In server side you have to add this coding by using grid view properties------

  Sub loadde()
        fselect = "select * from phone"
        'sselect = "select *from phone where Number='" & txtPhonno.Text & "'"
        'r1table = obj.ExecuteData(sselect)
        rtable = obj.ExecuteData(fselect)


        GridView1.DataSource = rtable
        GridView1.DataBind()




You can find this event in Grid View properties......

Protected Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GridView1.RowEditing
        GridView1.EditIndex = e.NewEditIndex
        loadde()
    End Sub


Protected Sub GridView1_RowCancelingEdit(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles GridView1.RowCancelingEdit
        GridView1.EditIndex = -1
        loadde()


    End Sub
Protected Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridView1.PageIndexChanging
        GridView1.PageIndex = e.NewPageIndex
        loadde()


    End Sub


 Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GridView1.RowDeleting
           phonercd = GridView1.DataKeys(e.RowIndex).Value.ToString
        fselect = "delete phone where Number='" & phonercd & "'"
        obj.ExecuteCommand(fselect)
        loadde()
    End Sub
  
 Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridView1.RowUpdating
                fselect = "update phone set Name='" & Trim(rwname.text) & "',Address='" & Trim(rwaddress.Text) & "',City='" & Trim(rwcity.Text) & "',State='" & Trim(rwstate.text) & "' where Number='" & Trim(phonercd) & "'"
        obj.ExecuteCommand(fselect)
        GridView1.EditIndex = -1
        loadde()
    End Sub
  
plz post your valuable comments.....
  


Application ,Session,Cache and Cookies in ASP.NET


Hi friends ...This articles is fully discuss about basics cocept that every web developer should know the thing..

APLICATION:

Its really very intrested to read about application ..Application is used to store the variables and objects to use throughout the entire application.And also you can share the stored variable in all pages.
In moreover the application and session state are same concept the main difference between the application and session is that the session state store and share the variables for one particular user,whereas the application layer store variables that all user, share the information at the same time.

Let us see one examble for Apllication..

Now by using appliation i created the counter for tthe page ...

 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Application("counter") Is Nothing Then
            Application("counter") = 1
        Else
            Application.Lock()
            Application("counter") += 1
            Application.UnLock()
        End If
        Label1.Text = Application("counter")

    End Sub

In client side you have to add one label...
in serve side in load event just add the codings..
Now at the every time when the page load the counter will increment the count.This count store the variables for that all user using the page.

SESSION STATE:

Like application state the session state are used to store the temporary infromation in this page.But in session state the variable store the value for the current user using the page,But its deosnot the share the information to all user like application.
if you want to store the temporary infomation regarding the current use ,we can use session

textbox1.text=Session("username")
we can use the session for all pages in the application..
After closing the browser sesion has end at the particular time,this time property has set in GLOBAL.ASAX page.

CACHE:

cache is like similar to application,Both have shared the data between all user using the web application
By using insert the data is stored into cache ans also we have set the time using the time sapn till the time the data is present in the cache.
Cache.Insert("User", UserTable, Nothing,
DateTime.MaxValue, TimeSpan.FromMinutes(10))


COOKIES:
If you want to store data related to a particular user, you could use the Session object,but in session has as an important drawback: its contents are lost when the user closes the browser window
To store user data for longer periods of time, you need to use cookies .Cookies are not lost when the browser is closed (unless the user deletes them), so you can save data that helps identify your user in a cookie.