1

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

5 Answers 5

1

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
Sign up to request clarification or add additional context in comments.

Comments

0

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.

2 Comments

Can't use just make Save() a Page Method and then call it from client-side via AJAX?
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.
0

Is it possible to do something like

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

1 Comment

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.
0

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);

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.