2

I have a Javascript function that pulls down variables, like so:

   function OnClientCloseSecure(oWnd, args) {
       var arg = args.get_argument();

       if (arg) {
           var ResultCode = arg.ResultCode;
           var PONumber = arg.PONumber;
       }
   }

I need to assign ResultCode and PONumber to a variable in C# or if that isn't possible a label in c#.

Are any of these options possible? If so, how would I go about doing that? I've tried several things with no luck. Thanks!

3 Answers 3

5

One way would be to create hidden value and set the runat attribute to server. you can get the value.

    <script type="text/javascript">
   function abc() 
    { 
      var str="value"; 
      document.getElementById("Hidden1").value=str; 
    } 

    </script> 

<input id="Hidden1" type="hidden" runat="server" />

Code Behind:

    string value = Hidden1.Value;
Sign up to request clarification or add additional context in comments.

2 Comments

The following is C# code? string value = Hidden1.Value; how do you define Hidden1? what type is Hidden1?
You cant reach Hidden1.Value like that.
0

JavaScript

<script type="text/javascript">
    function OnClientCloseSecure(oWnd, args) {
        var arg = args.get_argument();
        if (arg) {
            var ResultCode = arg.ResultCode;
            var PONumber = arg.PONumber;
            document.getElementById('<%=lbl.ClientID %>').innerHTML = ResultCode;
        }
    }

</script> 

Mark Up

<asp:Label ID="lbl" runat="server" ></asp:Label>

Comments

0

For the ASP.NET MVC you can use:

@model ImageModel

<form method="post">
  @Html.HiddenFor(x=>x.ImageModel,new {@id="varA"})
<button>Click Me</button>
</form>

<script>
document.getElementById('varA').value = VarB;
</script>

As you can see, we assigned js value using 'id' and now when we post the form, js variable is accesible from the MVC Controller.

Comments

Your Answer

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