ASP.NET 2.0 and AJAX little problem....

Last post 02-23-2007 4:48 AM by paul.vencill. 2 replies.

Sort Posts:

  • ASP.NET 2.0 and AJAX little problem....

    02-22-2007, 3:07 PM
    • Member
      point Member
    • dany651
    • Member since 11-28-2006, 7:18 PM
    • Posts 1

    Hi eveyone, i start using AJAX (with asp.net 2.0 and vb) and i have a problem  :
    if i don't decleare my function GetDataPanel  as shared ajax don't find it (no error but simply don't reach the function in debug mode).

    - Why does my GetDataPanel function need to be "shared" ?
    - There's a way to don't have to declare my function as shared ? (or a way to have access to my control and function in my web form from a shared function ???)

    Expected result : get the text from a textbox in my webform from my GetDataPanel function

    Here is the code i use to call this function

    'This button call the javascript
    <input id="Button1" type="button" name="button1" value="OK" onClick="updateDateKey();" />

    'My javascript
        function updateDateKey() {
            var behavior = $find('dpe');
            if (behavior) {
                behavior.populate();
            }
        }

    'My AJAX control
                <cc1:DynamicPopulateExtender ID="dpe" ClearContentsDuringUpdate="true" ServiceMethod="GetDataPanel" runat="server" TargetControlID="Panel1">
                </cc1:DynamicPopulateExtender>

    'VB Function called from the ajax control
            <System.Web.Services.WebMethod()> _
            Public Shared Function GetDataPanel() As String
                Return TextBox1.Text
            End Function

    Thanks a lot

    DanyBoy

  • Re: ASP.NET 2.0 and AJAX little problem....

    02-23-2007, 3:41 AM
    • Contributor
      2,460 point Contributor
    • Steve Marx
    • Member since 05-26-2006, 8:35 PM
    • Microsoft
    • Posts 643

    It does have to be "Shared", and no, you can't access the other controls on the page (because the page is not instantiated).

    Why not use an UpdatePanel instead of the DynamicPopulateExtender?  That works like a regular postback (but doesn't reload the page), so you could use values from other controls.

    Steve Marx | ASP.NET AJAX Evangelist | Microsoft Corporation
  • Re: ASP.NET 2.0 and AJAX little problem....

    02-23-2007, 4:48 AM
    • Contributor
      6,620 point Contributor
    • paul.vencill
    • Member since 02-01-2006, 7:57 AM
    • Gaithersburg, MD
    • Posts 1,350
    Another technique would be to pass the value you want to use (textbox value, for example) as a parameter of the webmethod.
    Help those who have helped you... remember to "Mark as Answered"
Page 1 of 1 (3 items)