Pass the manufacturer part number to javascript link

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
13 years ago
hi,

I've inherited a 1.40 nopcommerce install (heavily customised with custom applications bolted in- so i'd like to avoid an upgrade now if possible) and have the coding ability of an early anthropoid. Is there a way i can pass the manufacturers part number to a piece of javascript code (the code returns information to the manufacturer)?

I'm trying to achieve this in the productprice.ascx file (so it links when the price is displayed) - I've got the script functioning just not with a variable for the partnumber.

Grateful for any assistance
13 years ago
Hello mrwillis,

I'd be curious to see your javascript code and what you are trying to do. Both out of curiosity and maybe to suggest a different way to solve your problem.

Thing is, you can't "pass" variables from codebehind to clientside code.
http://img265.imageshack.us/i/imagewzyv.jpg/

For general information you could look into stuff like:

1. Code Blocks:

C#:
protected string TempString="Test string";

Javascript:
var temp="<%=TempString%>";


Of course this only works if you know your manufacturing number when the page loads. If you try this out, have a look at the Page Source, there is no variable, just some text...

2. You can pass the whole Javascript function:

Response.Write("<script>alert('manufacturing number')</script>");

This is less bad than it looks like.

3. You can sneak in some value into a hidden field on the aspx page:
C#:
manufacturingnumber.value = "1";

Javascript:
<input type=hidden id=manufacturingnumber runat=server id=manufacturingnumber>

People on the internet recommend that all the time.

4. A complicated solution would be JSON/Webservices

  jQuery(function ($) {
        $("#Button1").click(function () {
            $.ajax({
                type: "POST",
                contentType: "application/json; charset=utf-8",
                url: "WebService1.asmx/HelloWorld",
                data: "{a:'" + "World" + "'}",
                dataType: "json",
                success: activateFunctionsCallback
            });
        });
    });
    function activateFunctionsCallback(data) {
        alert(data["d"]);
    }


C#:

[WebService(Namespace = "http://xtempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // Um das Aufrufen dieses Webdiensts aus einem Skript mit ASP.NET AJAX zuzulassen, heben Sie die Auskommentierung der folgenden Zeile auf.
    [System.Web.Script.Services.ScriptService]
    public class WebService1 : System.Web.Services.WebService
    {

        [WebMethod(EnableSession = true)]
        [ScriptMethod(UseHttpGet = false, ResponseFormat = ResponseFormat.Json)]
        public string HelloWorld(string a)
        {
            return "Hello " + a;
        }
    }


With this you can actually take user input, do something with it server-side, like look up a manufacturing number, and return it to a script client side. If you want to go that route you can copy+paste most of the code above, play around with it, pick up a bit "jQuery", check out "Webservices" and realize that this is all asynchronous and a bit slow, so that it's just a workaround as well.

But do tell us more about what code you have and what you are trying to do!
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.