Showing posts with label VB. Show all posts
Showing posts with label VB. Show all posts

Wednesday, 27 June 2012

Remove ViewState from ASPX Page.



Just Copy/Paster following Code in your Code.
 
Protected Overrides Function LoadPageStateFromPersistenceMedium() As Object
        Return (New LosFormatter().Deserialize(DirectCast(Session("ViewState"), String)))
    End Function

    Protected Overrides Sub SavePageStateToPersistenceMedium(ByVal state As Object)
        Dim los As New System.Web.UI.LosFormatter()
        Dim sw As New System.IO.StringWriter()
        los.Serialize(sw, state)
        Dim vs As String = sw.ToString()
        Session("ViewState") = Nothing
        Session("ViewState") = vs
    End Sub

Thursday, 14 June 2012

AutoCompleter in Ajax

Register Assembly in Page Directive :

<%@ Register Assembly="AjaxControlToolkit"
                    
 Namespace="AjaxControlToolkit"
                      TagPrefix="cc1" %>

IN HTML 00Test.aspx:
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:TextBox ID="txt" runat="server”></asp:TextBox>
 <cc1:AutoCompleteExtender ID="AC" runat="server"
                            
EnableViewState="False"
                             FirstRowSelected="True"
ServicePath="00Test.aspx"
ServiceMethod="ListSearch"
TargetControlID="txt"
DelimiterCharacters=":,;"
CompletionListCssClass="ac_completionListElement" CompletionSetCount="10"
CompletionListItemCssClass="ac_listItem" CompletionListHighlightedItemCssClass="ac_highlightedListItem"
                             MinimumPrefixLength="1"
CompletionInterval="1000"
OnClientItemSelected="MY" >
</cc1:AutoCompleteExtender>

In Code behind 00Test.aspx.vb:

Partial Class _00Test
    Inherits System.Web.UI.Page

<System.Web.Services.WebMethod()> _
<System.Web.Script.Services.ScriptMethod()> _
  Public Shared Function ListSearch(ByVal prefixText As String,
                                                ByVal count As Integer) As String()
 If count > 0 Then
    Dim con As New SqlClient.SqlConnection("Connestion String")
    Dim cmd As New SqlClient.SqlCommand("USP_Page", con)
    cmd.CommandType = CommandType.StoredProcedure
    cmd.Parameters.AddWithValue("@SearchTxt", prefixText)
    Dim DT As New DataTable
    Dim DA As New SqlClient.SqlDataAdapter(cmd)
    DA.Fill(DT)
    Dim lstCode As New Generic.List(Of String)
    For i As Integer = 0 To DT.Rows.Count - 1
         lstCode.Add(DT.Rows(i)("AutoSearch").ToString)
    Next
       Return lstCode.ToArray
    End If
    End Function
End Class


// call back function onItemSelect
    this function will called when any item will selected from AC List
function MY(source, eventArgs) {

            alert(eventArgs._text);

        }

.css
.ac_completionListElement
{
    padding-left: 0px;   
    background-color: inherit;
    color: #696969;
    border: 1px solid buttonshadow;       
    text-align: left;
    list-style-type: none;
    margin-top:0;
}

/* AutoComplete highlighted item */

.ac_highlightedListItem
{
    background-color: #EAF1F7;
    color: black;
    padding: 4px
    cursor:pointer
}

/* AutoComplete item */

.ac_listItem
{
    background-color: window;
    color: #696969;
    padding: 4px;
   
}


Wednesday, 13 June 2012

Call Ajax Method from JavaScript



Hi   Friends..
Here is Some Simple Coding About HOW TO CALL SERVER SIDE METHOD FROM JAVASCRIPT

1 .  Write HTML For Any Control from which You want to Call Javascript as Follow, Here We
      Have A button on Its Click Event JS Function will Called.

<input type="button" value="sd" onclick="me();" />

2.   Now Write Java Script Function that Call Server Side Method
<script type="text/javascript">
        function me() {
        var result = _00Test.Hello();
        alert(result.value);
        }
</script>
     Here  “_OOTest” is the class Of Page  and “Hello()” is function Name, result will
     Occupy value that returns from called function.

3.   Now Create Ajax Method in Code Behind Like :

Imports Ajax

Partial Class _00Test
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
                            Handles Me.Load
           Ajax.Utility.RegisterTypeForAjax(GetType(_00Test))
    End Sub
    ''' <summary>
    '''  Function That Called from JavaScript
    ''' </summary>
    <Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.ReadWrite)> _
    Public Function Hello() As String
        Return "Ajay Patel"
    End Function
End Class

     In this we have Used Ajax to call Server Side Method without Postback Of Page
     function “Hello()”  Contains attribute like “<Ajax.AjaxMethod(…)>” which Point
     that this method is Ajax Method that we can Call from JavaScript.

    
     This Is Simple Example about How to call Server side method using  JavaScript