Showing posts with label itself. Show all posts
Showing posts with label itself. Show all posts

Monday, March 26, 2012

Ajax auto complete extender

I am using ajax autocompleteextender. I have declared the service method in the user control itself instead of declaring it in aspx page. But the extender does not work .How can i do it? I want to declare it in ascx page,as i will be reusing the component.

my master page script
=====================
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true" EnablePartialRendering="true"/asp:ScriptManager
my aspx page where i am inheriting masterpage
==============================================

<%@. Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="frmTestAuto.aspx.cs" Inherits="frmTestAuto" Title="Untitled Page" %>
<%@. Register src="http://pics.10026.com/?src=ctlAutoExtender.ascx" TagName="ctlAutoExtender" TagPrefix="uc1" %>
<%@. Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server" /asp:ScriptManagerProxy>
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<tr>
<td>TEST AUTO PAGE</td>
</tr>
<tr>
<td>uc1:ctlAutoExtender ID="CtlAutoExtender1" runat="server" /</td>
</tr>
<tr>
<td>Footer</td>
</tr>
</table>
</asp:Content
my ascx page
=============
<%@. Control Language="C#" AutoEventWireup="true" CodeFile="ctlAutoExtender.ascx.cs" Inherits="ctlAutoExtender" %>
<%@. Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server"></asp:ScriptManagerProxy>
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<tr>
<td>
<asp:TextBox runat="server" ID="myTextBox" Width="300" />

<ajaxToolkit:AutoCompleteExtender runat="server" ID="autoComplete1" TargetControlID="myTextBox" Enabled="true"
ServiceMethod="GetCompletionList" ServicePath="ctlAutoExtender.ascx.cs" MinimumPrefixLength="3"
CompletionInterval="1000" EnableCaching="true"
CompletionSetCount="12"/>
</td>
</tr>
</table
my ascx.cs page
===============

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Web.Services;
using System.Web.Script.Services;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService]

public partial class ctlAutoExtender : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{

}

[WebMethod]
[ScriptMethod]
public static string[] GetCompletionList(string prefixText, int count)
{
string sql = String.Format("select clt_tVLongNm from mclient where clt_tVLongNm like @.companyname + '%'");

List<string> companyList = new List<string>();

using (SqlConnection connection = new SqlConnection("server=192.168.2.57;uid=sa;pwd=d28rg6yp;database=fnocash_report"))

using (SqlCommand command = new SqlCommand(sql, connection))
{
connection.Open();
command.Parameters.AddWithValue("@.companyname", prefixText);
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
companyList.Add(reader.GetString(0));
}
}
}
return companyList.ToArray();
}
}

please help me out asap


Hi,

In ASP.NET, a request for a .ascx file will be?handled?by?System.Web.HttpForbiddenHandler?HttpHandler,?that's?to?say,?it's?refused.
So you can't use a method in the UserControl, I suggest trying to use a web service(.asmx) to achieve this.
Hope this helps.

Hi,

I am declaring the autocompleteextender in the user control. So, should I give service path for the extender as .asmx file in the extender?

eg:

My ascx page:

<%

@.ControlLanguage="C#"AutoEventWireup="true"CodeFile="ctlAutoExtender.ascx.cs"Inherits="ctlAutoExtender" %>

<%

@.RegisterAssembly="AjaxControlToolkit"Namespace="AjaxControlToolkit"TagPrefix="ajaxToolkit" %>

<

tablecellpadding="0"cellspacing="0"border="0"width="100%"><tr><td><asp:TextBoxrunat="server"ID="myTextBox"Width="300"/>

<ajaxToolkit:AutoCompleteExtenderrunat="server"ID="autoComplete1"TargetControlID="myTextBox"Enabled="true"ServiceMethod="GetCompletionList"ServicePath="App_Code/WebService.cs"MinimumPrefixLength="3"CompletionInterval="1000"EnableCaching="true"CompletionSetCount="12"/></td></tr>

</

table>


Yes,?like?this:??ServicePath="the relative path of the .asmx file"
Thanks, that solved my problem.

Ajax and WebParts

I am building a site that uses Web Parts and Ajax. In each Web Part I have a user control that uses Ajax to update itself. All the user controls use Ajax. Everything works well until, I close one of the web parts.When I do this and click on any of the controls to do an update, I get an error Sys.InvalidOperationException: Could not find UpdatePanel with ID <name of the panel that contained the web part that I closed>. If it is being updated dynamically then it must be inside another update panel.

Since all the controls use Ajax, how can i overcome the fact that the script is looking for the controls found in another Web Part.

1.Try to take a look at this useful blog about Dragging and dropping ASP.NET 2.0 Web Parts in Firefox and Safari with ASP.NET AJAX -http://blogs.neudesic.com/blogs/david_barkol/archive/2006/11/07/631.aspx
2.Try to read this thread - http://forums.asp.net/thread/1486784.aspx to get some ideas.
Here are some sample codes about using webParts in Ajax for your reference.
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="upPortal" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:WebPartManager ID="wpmPortal" runat="server">
</asp:WebPartManager>
<div class="wrapper">
<asp:CatalogZone ID="czPortal" runat="server">
</asp:CatalogZone>
</div>
<div class="wrapper">
<div id="wz1">
<asp:WebPartZone ID="WebPartZone2" runat="server" HeaderText="Column 1">
<ZoneTemplate>
<asp:Wizard ID="Wizard1" runat="server">
<WizardSteps>
<asp:WizardStep ID="WizardStep1" runat="server" Title="Step 1">
</asp:WizardStep>
<asp:WizardStep ID="WizardStep2" runat="server" Title="Step 2">
</asp:WizardStep>
</WizardSteps>
</asp:Wizard>
<%--<uc1:ThemeSelector ID="ThemeSelector1" runat="server" EnableTheming="True" />--%>
</ZoneTemplate>
</asp:WebPartZone>
</div>
<div id="wz2">
<asp:WebPartZone ID="WebPartZone3" runat="server" HeaderText="Column 2">
<ZoneTemplate>
<asp:Calendar ID="Calendar1" runat="server" BackColor="White" BorderColor="Black"
DayNameFormat="Shortest" Font-Names="Times New Roman" Font-Size="10pt" ForeColor="Black"
Height="220px" NextPrevFormat="FullMonth" TitleFormat="Month" Width="312px">
<SelectedDayStyle BackColor="#CC3333" ForeColor="White" />
<TodayDayStyle BackColor="#CCCC99" />
<SelectorStyle BackColor="#CCCCCC" Font-Bold="True" Font-Names="Verdana" Font-Size="8pt"
ForeColor="#333333" Width="1%" />
<DayStyle Width="14%" />
<OtherMonthDayStyle ForeColor="#999999" />
<NextPrevStyle Font-Size="8pt" ForeColor="White" />
<DayHeaderStyle BackColor="#CCCCCC" Font-Bold="True" Font-Size="7pt" ForeColor="#333333"
Height="10pt" />
<TitleStyle BackColor="Black" Font-Bold="True" Font-Size="13pt" ForeColor="White"
Height="14pt" Font-Names="Arial" />
</asp:Calendar>
</ZoneTemplate>
</asp:WebPartZone>
</div>
<div id="wz3">
<asp:WebPartZone ID="WebPartZone4" runat="server">
<ZoneTemplate>
<asp:Login ID="Login1" runat="server">
</asp:Login>
<asp:Login ID="Login2" runat="server">
</asp:Login>
</ZoneTemplate>
</asp:WebPartZone>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div
Can you send your website to my email:v-jicwan@.microsoft.com? I'd?like?to?test?it.

Hi Jasson,

Thanks for the information. I found the problem. Each of my user controls are inside an UpdatePanel tag. I had missed adding the attribute UpdateMode="Conditional". Once I added this attribute everything worked fine.

Thanks once again


Hi vinod,

I have the same problem. i have try your solution ...its working but it will referesh the page..

i want to work it without refereshing the page. is it possible.

waiting for your reply.

thanks in advance

vishnu


Hi vinod,

I have the same problem. i have try your solution ...its working but it will referesh the page..

i want to work it without refereshing the page. is it possible?.

please try to send sample code.

waiting for your reply.

thanks in advance

vishnu