Solved

asp.net - call a sub on the server side...even though its shared...

Posted on 2011-02-16
4
346 Views
Last Modified: 2012-05-11

 How can I call a
------

   <WebMethod()> _
    Public Shared Sub SetVariable(ByVal textVal As String,)
        HttpContext.Current.Session("SessionUserFirstName") = textVal
   
        call_this_sub(textVal)

    End Sub
0
Comment
Question by:GlobaLevel
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 10

Author Comment

by:GlobaLevel
ID: 34911573
this isnt working;

 HttpContext.Current.Application(do_this(textVal))
0
 
LVL 12

Expert Comment

by:Pra4444
ID: 34911745
Try creating a new instance of your class that contains the above webmethod and call the sub..

dim myClass as New WebMethodClass
myClass.do_this(textVal)

0
 
LVL 10

Author Comment

by:GlobaLevel
ID: 34917790
Pra4444....

thats not working for me...


Imports System.Data.SqlClient

Imports System.IO
Imports System.Data.SqlClient.SqlDataAdapter
Imports System.Data.SqlClient.SqlConnection
Imports System.String
Imports System.StringComparison
Imports System.Text.StringBuilder
Imports System.Web.UI
Imports System.Web.UI.Page
Imports System.Web.UI.WebControls.TextBox
Imports System.Web.UI.WebControls
Imports System.Web.UI.ExtenderControl
Imports System.Random
Imports System.DateTime
Imports System.Data.OleDb
Imports System.Text
Imports System.Data.Odbc
Imports System.Data
Imports System.Text.RegularExpressions
Imports System.Collections.Generic
Imports System.Linq
Imports System.Web
Imports System.Web.Services
Imports System.Web.SessionState.HttpSessionState


Partial Class client_online_srvnt
    Inherits System.Web.UI.Page



    <WebMethod()> _
    Public Shared Sub SetVariable(ByVal textVal As String)
        HttpContext.Current.Session("SessionUserFirstName") = textVal
        ' do_this(textval)
        dim myClass as New WebMethodClass
        MyClass.do_this(textVal)


    End Sub

    Public Sub do_this(ByVal textvlas As String)



    End Sub

End Class

Open in new window

0
 
LVL 12

Accepted Solution

by:
Pra4444 earned 500 total points
ID: 34918009
Ok...maybe i didnt explain it right....

There are two ways in which you can do it...

one is.... change ur function definition like this..

private shared sub do_this(byval textval as String)

  code for your function...

end sub

call from your webmethod as usual.....



Second way...

Partial Class client_online_srvnt
    Inherits System.Web.UI.Page
   <WebMethod()> _
    Public Shared Sub SetVariable(ByVal textVal As String)
        HttpContext.Current.Session("SessionUserFirstName") = textVal
        ' do_this(textval)
        dim myClass as New HelperClass
        MyClass.do_this(textVal)


    End Sub
'create a new class and write the sub that you need to access....
Public Class HelperClass
    Public sub do_this(byval textval)
                do ur code here...
    End sub
End Class
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
What are MicroServices? 4 67
Ajax success not firing alert 6 39
Could copy the reset.css and site.js from production website? 2 39
Jquery syntax 12 29
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question