Link to home
Start Free TrialLog in
Avatar of avacaralife

asked on

How to pass javascript parameter to C# fucntion parameter

Hii Dear
I have problem to call c# function from javascript with parameter which is pass in javascript function.

Its work fine if there is no parameter. But I want to pass javascript parameter value to C# function.

I have try following way.

<script type="text/javascript">    
function EventTrack(pIntEventID,pIntCategoryID,pLngMemberID,pStrAttributeA,pStrAttributeB,pStrAttributeC,pStrAttributeD,pStrAttributeE)
          var  lIntEventID=pIntEventID;            
          var  lIntCategoryID = pIntCategoryID;
           var lLngMemberID = pLngMemberID;
           var lStrAttributeA = pStrAttributeA;
           var lStrAttributeB = pStrAttributeB;
           var lStrAttributeC = pStrAttributeC;
           var lStrAttributeD = pStrAttributeD;
           var lStrAttributeE = pStrAttributeE;            
            //This is the function in C# page code
            <% trackEvent(%> lIntEventID <%=,%> lIntCategoryID <%=,%> lLngMemberID <%=,%> lStrAttributeA <%=,%> lStrAttributeB <%=,%> lStrAttributeC <%=,%> lStrAttributeD <%=,%> lStrAttributeE <%=);%>
            return true;

Thanks in advance
Avatar of Mlanda T
Mlanda T
Flag of South Africa image

I am doubtul about your approach here. You need ot realise that your Javascript code executes at the client side, and the c# code on the server side. You cannot pass 'parameters' in the manner you are attempting.

You need to perhaps create a number of textboxes or hidden input controls on the form and set the values of those textboxes, then initiate a postback which causes the necessary processin to be done on the server side.
Hi avacaralife,

Have you seen anything about PageMethods before? I was looking to call C# functions using javascript not too long ago and this is the best solution I could find.

Hava a look at these for some examples and info:
Avatar of avacaralife


Thanks MlandaT,
Ok I will try the way suggest.
But if possible then I need to pass from java script.
Avatar of Mlanda T
Mlanda T
Flag of South Africa image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SandyAgo's approach is also interesting.. I actually wasnt aware you could do that myself.
Thanks MlandaT,

Ok I will try this and reply you.
Solutions were provided but no feedback was eventually given as to whether they helped find a working solution