views:

341

answers:

5

I have vb.net method and i call it from JS code i can't send parameter to this method and here is sample: JS Code :

function OnSave() 
    {
        var sign = document.FORM1.SigPlus1.Signature();
        <%Save(sign) %>
    }

VB method :

Public Sub Save(ByVal obj As Object)
    Dim obj1 As New PFSIGNATURELib.SigniShellSignature
    obj1.SignatureBytes = obj
    obj1.SaveBitmapToFile(CurDir() & "\sign1.bmp", 200, 200)
    signImg.Src = CurDir() & "\sign1.bmp"

End Sub
A: 

There is no easy way to do it.

Your best bet is to create a web service call, and have Javascript call the web service using ASP.NET Ajax.

Here is a way to do that.

David Basarab
Can't use just make Save() a Page Method and then call it from client-side via AJAX?
Russ Cam
How do you convert the object? The web service does that well for you. I haven't been able to do it successfully, I have done it with a web service. Or another way I have done it is hook up to a hidden button, but that is much more complicated.
David Basarab
+1  A: 

Well actually you can do it in an "easy" way:

Add a hidden LinkButton to you page:

<asp:LinkButton runat="server" id="MyPostBackHelper" style="display: none;" />

then in your javascript:

function OnSave() 
{
    var sign = document.FORM1.SigPlus1.Signature();
    __doPostBack(<%= MyPostBackHelper.UniqueID %>, sign);
}

and then in the codebehind:

Public Sub MyPostBackHelper_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyPostBackHelper.Click
  Dim obj1 As New PFSIGNATURELib.SigniShellSignature
  obj1.SignatureBytes = Request.Form("__EVENTARGUMENT")
  obj1.SaveBitmapToFile(CurDir() & "\sign1.bmp", 200, 200)
  signImg.Src = CurDir() & "\sign1.bmp"
End Sub
Sani Huttunen
A: 

Is it possible to do something like

<%Save(%>sign<%) %> ?

Robert
No... If you execute "Save(" you'll get an error. Same goes for ")". you cannot mix and combine VB.NET and Javascript statements that way.
Sani Huttunen
A: 

Could you not use the ajax libraries built into .net 3.5 and mark your method as a web Method

       <WebMethod()> _
    Public Shared Function SaveParamsData
End sub

Then use javascript to call that method.

PageMethods.SaveParamsData(ReportItemPramName, MyMethod_Result);
Antony Delaney
A: 

hmm, could you not cause the javascript to post the data back to the page. then check to see if there is postdata on page load, if there is, then save it

zeocrash