9:22 PM

Default Button in ASP.net

Posted by vijay


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...




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.....
  



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.