Saturday 22 December 2012

Difference between Hidden Field and Viewstate in asp.net. | Vb.Net

Difference between Hidden Field and Viewstate in asp.net. | Vb.Net

In asp.net hidden field and Viewstate both manage memory management.
we can store value in hidden field and viewstate also.
now lets check the difference between both

1->Hidden Field is server control and Viewstate is variable .
2->Hidden field won't visible in browser same for Viewstate but if we will use hidden field ,
 we will get more extra encrypted code in view source whereas if we will use Viewstate we will not get that much of extra code.
3-><input type="hidden" id="hdn" runat="server">
To assign value  to hidden field .. use value property of hidden field
 hdn.Value="sometext" // assingning value  to hidden field
lablet.text=hdn.value   // storing value of hidden field into variable

For viewstate
Viewstate("storeval")="sometext" // assigning value into viewstate
string str=Viewstate("storeval")   //storing value of viewstate into variable
in c# syntax is different.

so in these way we can use hidden field and view state.
hidden field go to the server but Viewstate maintain  after postback whithout touching server.

I don't know whether we can store Datatable value in hidden field but its possible in Viewstate.


Sunday 16 December 2012

Alert in asp.net on code behind page with vb.net

Alert in asp.net on code behind page with vb.net

 Protected Sub btnEnter_Click( ) Handles btnSubmit.Click

      Dim str As String
    str = "select field1 , field2 from table_name where field1=" & Trim(txtval.Text) & " and field2='somevalue' and tdate='"

& txtdate.SelectedDate & "'"
            Dim datareader_rad As SqlClient.SqlDataReader
            Dim sqlcommandname As New SqlCommand(str, con)
            con.Open()

           datareader_rad= sqlcommandname.ExecuteReader

            If datareader_rad .Read Then
                Try
     Response.Write("<script language='javascript'>alert('already value is  there in list.');</script>")
                Catch ex As Exception
                Finally

                    con.Close()

                End Try
            Else
                con.Close()
                dr.Close()

                Try
                    cmd = New SqlCommand("stoted_procedure_name", con)
                    cmd.CommandType = CommandType.StoredProcedure
                    cmd.Parameters.AddWithValue("@field1", Trim(txt1.Text))
                    cmd.Parameters.AddWithValue("@tablefield2", Trim(txt2.Text))
                    cmd.Parameters.AddWithValue("@time", Trim(txttime.Text))
                       Catch ex As Exception
                End Try
            End If
        End Sub
What  i did here just took one datareader and stored value ,  means stored field all value into datareader then checked using datareader_rad .read it shows if value already present in datareader then will show alert box that "already value is  entered".

     Response.Write("<script language='javascript'>alert('already value is  entered.');</script>")
by this code we can learn about javascript in  code behind  page in asp.net using vb.net



c program | Sorting of given number | implementation of Insertion sort

c program | Sorting of given number  |  implementation of Insertion sort

Logic and examples to sort given number in list.
In this article we will get idea about to sort number .
user will enter the number in any order like 4,5,3,67,8, etc..
and when we include in program it will get output like 3,4,5,8,67.
before to sort given number all the entered number will save in list .
then after it will sort by ascending order like small to bigger number and will show in ordered .
this program we call as Program for implementation of Insertion sort also.

#include<stdio.h>// header file
#include<conio.h>
#define max 20

void main() // start of main
{
int i,j,n,k,t,temp,a[max];//intializing variable and temp memory
clrscr();
printf("\How many no. you want to insert into list:- ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\nEnter %d no:- ",i+1);
scanf("%d",&a[i]);
}
printf("\nUnsorted list is:-\n");// will display unsorted list
for(i=0;i<n;i++)
printf("\n%d",a[i]);
for(i=1;i<n;i++)
{
for(j=0;j<i;j++)
{
if(a[i]<a[j])// cheking first value is less than next one
{
temp=a[j];
a[j]=a[i];
for(k=i;k>j;k--)
a[k]=a[k-1];
a[k+1]=temp;
}
}
}
printf("\n\nSorted list is:-\n");// will print sorted order in a list
for(i=0;i<n;i++)
printf("\n%d",a[i]);
getch();
}