1

here is my jQuery:

    $(document).ready(function () {
        var image = $('#man');

        var legTooltip = 'LEG';

        image.mapster({
            fillOpacity: 0.5,
            mapKey: 'alt',
            fillColor: "000000",
            listKey: 'alt',
            scaleMap: falsee,
            singleSelect: true,
            toolTipClose: ["tooltip-click", "area-click", "area-mouseout"],
            showToolTip: true,
            onClick: function (e) {
                if (e.key === 'leg') {
                   var **symp** = e.key;                        
                }                    
            },
            areas: [
            {
                key: "leg",
                toolTip: legTooltip
            }],
            render_highlight: {
                fade: false
            }                
        });
    });

now how can i send the value of variable symp into server side cs file and save the value into another server side variable? i have little knowledge about jquery and asp.net. thanks in advance.

2
  • use ajax and send that variable value to server side. Commented Oct 23, 2016 at 8:41
  • thanks for ur advice. i start learning ajax@Div Commented Oct 23, 2016 at 11:32

3 Answers 3

1

If I understand you right, you need to send a post request to server. You can do it by using jQuery method post (which is a shorthand Ajax function).

$.post( 
    "YourController/YourMethod", 
    { symp },
    function( response ) {
        //proccess the response here
    }
); 

On the server side add a method in your controller which will get this value

public class YourController : Controller
{
    //other methods and fields

    [HttpPost]
    public ActionResult YourMethod(<type of variable symp> symp)
    {
        //save this value wherever you want
        //return result of your request, so you can proccess it on the client side
        //e.g. that operation was successfully completed
    }
}
Sign up to request clarification or add additional context in comments.

Comments

0

Try ajax:

$.(ajax){(
    url : 'url of the file in which yo want to process the data',
    method: 'post or get',
    data: {
        var1 : value1,
        var2 : value2    
        // these variables are available on the specified url  
        // use your variable(symp) here
    },
    success: function(response)
    {
         // response hold the server side response in it.
    }
)}

Do not forget to include the jquery library in your code.

1 Comment

thanks...as i new in jquery and ajax can you plz tell me where i write this code?
0

If the value of symp needs to be updated continuously, then Ajax would be better as Mayank Pandeys answer. But if you only need the value on PostBack, a HiddenField would be easiest.

<asp:HiddenField ID="HiddenField1" runat="server" />

if (e.key === 'leg') {
    var **symp** = e.key;
    document.getElementById("<%= HiddenField1.ClientID %>").value = symp;
}

And then you can use the value of symp in code behind by getting the value from the HiddenField.

string symp = HiddenField1.Value;

1 Comment

thanks for your advice. for my project i needs to be updated continuously. but ur suggestion is also helpful for me as i can use it another page.

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.