views:

1400

answers:

2

Hi!

I created a AutoCompleteExtender on a TextBox that resides on a UserControl (Control.ascx file).

I don't want to create a separate class for the web method, i rather placing it in the code file (Control.ascx.cs) itself.

Is there a way?

I have successfully tried once ago placing the method on the same page but it was a page, and if ServicePath property is not set it's automatically refered to the page so it worked, now since it's a user control it doesn't even when I explicitly specify the path.

A: 

The AutoCompleteExtender does not work within a UserControl at this time. Quoting Dino Esposito in MSDN Magazine Feb 2007: -

A callable page method is a public static (or Shared in Visual Basic.NET) method defined in the codebehind class and decorated with the same WebMethod attribute used for Web service methods. At present, this is limited to ASPX pages-both inline and codebehind code-but might be extended in the future to user controls and custom controls.

My recent experience shows this still holds true.

I'm afraid that you're left with either implementing the method as a WebService or moving the functionality back up to the page.

OtisAardvark
I will use jQuery
Shimmy
+1  A: 

You can actually keep the web method in .aspx while other autocomplete extender related code can reside in .ascx. It works fine.

Praveen