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
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.
Another technique would be to pass the value you want to use (textbox value, for example) as a parameter of the webmethod.
No comments:
Post a Comment