Monday, October 20, 2008

Using AJAX Auto complete Extender control in ASP.NET:

We often use Ajax controls in our projects. But simple mistakes make a project difficult.
I came across this problem by searching a lot in different forums and websites.
Now I am explaining full length of code in my blogspot.
AutoComplete is an ASP.NET AJAX extender that can be attached to any TextBox control, and will associate that control with a popup panel to display words that begin with the prefix typed into the textbox

IN ASP.NET

<form id="aspnetForm" name="aspnetForm" runat="server">
<asp:ScriptManager runat="server" />
<div class="demoarea">
<div class="demoheading">AutoComplete Control lab</div>
<p/>
Type something
:
<asp:TextBox runat="server" ID="myTextBox" Width="300" autocomplete="off" />
<AJAX:AutoCompleteExtender runat="server" ID="autoComplete1" TargetControlID="myTextBox" ServicePath="test.asmx" ServiceMethod="GetResults" MinimumPrefixLength="1"
CompletionInterval="1000"
EnableCaching="true"
CompletionSetCount="12" />

IN WEBSERVICE Test.vb

Imports System.Web
Imports System.Web.Services
Imports System.Web.Script.Services
Imports System.Web.Services.Protocols
Imports System.Data.SqlClient
Imports System.Data
Imports System.Collections.Generic

<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<System.Web.Script.Services.ScriptService()> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class WebService
Inherits System.Web.Services.WebService

<WebMethod(EnableSession:=True)> _
Public Function GetCompletionList(ByVal prefixText As String, ByVal count As Integer) As String()
Dim ds As New DataSet
Dim pre
Dim i As Integer
ds = Session("dsStyle")
If ds.Tables(0).Rows.Count <> 0 Then
Dim items As New List(Of String)
For i = 0 To ds.Tables(0).Rows.Count - 1
pre = ds.Tables(0).Rows(i).Item("matinfo")
If prefixText.ToLower = pre.Substring(0, prefixText.Length).ToLower Or prefixText.ToUpper = pre.Substring(0, prefixText.Length).ToUpper Then
items.Add(ds.Tables(0).Rows(i).Item("matinfo").ToString())
End If
Next
Return items.ToArray
End If

Here in this webservice,i got a data in dataset from sessions .To activate sessions in Webservice we have to include EnableSession:=True as mentioned above.Please let me know if there are any queries.
Thanks.

Sunday, October 19, 2008

Capturing a Event in .NET

If there are more controls in our application. In some cases,in every postback all events raise at a time.
So,at that time capturing an event is necessary.I have faced this problem,and i came up with this solution.Hope it will help u.
IMP : Call this Function in Page_Init

IN VB.NET

Function Getfieldname(ByVal targPage As Page) As String
vfieldname = ""
If targPage.IsPostBack Then
Dim keyName As String
For Each keyName In targPage.Request.Form
If Not keyName Is Nothing Then
If keyName.Length >= 41 Then
If keyName.Substring(0, 41) = "ctl00$ContentPlaceHolder1$ImgbtnConfigure" Then
vfieldname = "ADD"
rowid = keyName.Substring(41, 1)
End If
End If
End If
Next
End If
End Function

Thursday, October 16, 2008

Creating Dynamic Table in ASP.NET

The central point is, with ASP.NET, you need to forget HTML. Stop thinking of rendering a "table". Instead, use an ASP.NET Server Control. It will render the table.

Now,I am creating a dynamic(run time ) Table with a Textbox and Dropdownlist with 10 rows

And Here is the code

IN ASP.NET


<form id="form1" runat="server">
<div>
<asp:Table ID="table1" runat ="server" >
<asp:TableHeaderRow ID="TableHeaderRow1" CssClass="TableBorderHeadline" runat="server" >
<asp:TableHeaderCell ID="TableHeaderCell1" runat="server" >TextBox </asp:TableHeaderCell>
<asp:TableHeaderCell ID="TableHeaderCell2" runat="server" >Dropdownlist</asp:TableHeaderCell>
</asp:TableHeaderRow>
</asp:Table>
</div>
</form>




IN VB.NET

Public tblCol(10) As TableCell
Public tblRow(10) As TableRow
Public txtfirst(10) As TextBox
Public ddlfirst(10) As DropDownList


Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
Dim itemCount As Integer
For itemCount = 1 To 10
tblRow(itemCount) = New TableRow

'----this is for txtfirst textbox---------
tblCol(1) = New TableCell
txtfirst(itemCount) = New TextBox
txtfirst(itemCount).ID = "txtfirst" & itemCount
tblCol(1).Controls.Add(txtfirst(itemCount))
tblRow(itemCount).Cells.Add(tblCol(1))
table1.Rows.Add(tblRow(itemCount))


'------this is for ddlfirst dropdownlist------

tblCol(2) = New TableCell
ddlfirst(itemCount) = New DropDownList
ddlfirst(itemCount).ID = "ddlfirst" & itemCount
ddlfirst(itemCount).Width = "70"
tblCol(2).Controls.Add(ddlfirst(itemCount))
tblRow(itemCount).Cells.Add(tblCol(2))
table1.Rows.Add(tblRow(itemCount))
Next
End Sub