Running Client Side C# Using ASP.NET

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • steve_barker333@hotmail.com

    #1

    Running Client Side C# Using ASP.NET

    Hi guys!

    I found a great article a while ago about how to write client side C#.
    Sadly, I can't find it again now, but here's the jist of what I learnt
    to do:

    1. Write a C# (or any .NET language) dll.
    2. Write a web page in ASP.NET.
    3. Put the dll from 1 into the virtual directory that 2 lives in (the
    root).
    4. Use an object tag in the web page to download the dll onto the
    client machine when the page loads.
    5. Fire some javascript from within the web page to access methods in
    the dll client side, effectively running code from 1 on the client,
    with no need for post backs etc...

    This sounds too good to be true, right? It really does work! There is
    an obvious draw back: The client needs to have the .NET framework
    installed! This is obviously a problem if you want to expose your
    functionality across the whole of the web, but for a controlled area,
    such as a company network, this method can be a great way to deploy
    enhanced web applications. There's no installation needed (apart from
    the framework), and if the dll mentioned in 1 is updated, the web page
    automatically downloads the new version of the component. I have put
    this technology to great use within my company: I have written a web
    page that provides spell checking on text fields. Clearly, I don't want
    to send the page back to the server every time I want to check the
    spelling, so I have written a .NET dll that launches a contained form.
    Text from a HTML text box is passed to the form, which checks the
    spelling against a dictionary file embedded in my .NET dll. When the
    form (which is displayed as modal from IE) closes, the corrected text
    is put back into the HTML text box. Everything works dynamically.

    Here are some technical details:

    The object tag mentioned in 4 looks like this:

    <OBJECT id="textEditor "
    classid="http:C lientSideCode.d ll#ClientSideCo de.TextEditor" name="Text"
    VIEWASTEXT></OBJECT>

    Note that the classid is made up as follows: "http:{DLL File
    Name}#{Default DLL namespace}.{Cla ss name}

    The javascript function would then look like this:

    function EditText()
    {
    alert(textEdito r.EditText(docu ment.Form1.txtT ext.value);
    }

    ....assuming a control called txtText exists. Of course, the result from
    this call need not be put into a message. You can do anything with the
    return value, and pass a string from any source.

    The method that got called in the C# dll would look something like
    this:

    public string EditText(string Text)
    {
    //Implementation
    return Text;
    }

    However, and here is the but.... I've had this method working fine on a
    whole host of machines, but every now and then I find a machine that
    simply refuses to allow this method to work, even though the EXACT SAME
    code works fine on other machines.

    This is the message I get:

    Error: Object doesn't support this property or method

    I figure there must be a setting I need to tweak on these machines to
    make it work, but I have no idea what I'm looking for. Can anyone
    help!? I'm all out of ideas!

    Thanks in advance for your help!

    Steve.

  • Eric David

    #2
    Re: Running Client Side C# Using ASP.NET

    Steve,
    Kudos on the post! I think I know the article you're talking about...
    but I could be wrong. Is it this one?
    http://msdn.microsoft.com/msdnmag/is...h/default.aspx
    Also, the xml programming for .net book by Dino Esposito has an example
    of using a dll from Winforms on the client. I've had a similar problem
    to yours... but at a much simpler level. The code that is in the first
    article runs just fine when I run it from localhost/code, but if I try
    to execute the same page but by using mydomain/code it throws the same
    error as the one you're getting. My guess is that it could have
    something to do with security zones... and there's also sometimes (i
    humbly offer) a disconnect between the control and the javascript
    calling it... But if I find anything meaningful out I'll be sure to
    post it here. Hope that helps...

    E

    Comment

    • steve_barker333@hotmail.com

      #3
      Re: Running Client Side C# Using ASP.NET

      Eric,

      Thanks for your reply Eric, and for your kind words! The link you have
      included isn't the one I was thinking about, but it is similar. I've
      had the code in my example running from server to client on a LAN,
      using http:\\{IP}\etc ... addresses and http:\\{server name}\etc... It
      seems random as to which machines it will and won't work on at the
      moment! I've even had problems running the code on a single machine
      acting as both client and server, which is strange. Do you think it is
      due to restrictions imposed by IIS, IE, ASP.NET, .NET Framework or the
      machine itself? (That's a lot of choices!)

      I suspect that my problems are security related as well; no doubt it'll
      turn out to be a check box buried 10 menus deep that is missing a
      check! If anyone can locate this check box (or whatever it is!) I'd be
      very interested to hear what I need to do!

      Cheers,

      Steve.

      Comment

      • Nicholas Paldino [.NET/C# MVP]

        #4
        Re: Running Client Side C# Using ASP.NET

        Steve,

        Did you make sure that the permissions were granted for the assembly you
        are loading from the site? You have to go into the .NET Framework
        Administration for the version of .NET you are running, and make sure that
        the assembly that you are loading has the appropriate permissions.

        Hope this helps.

        --
        - Nicholas Paldino [.NET/C# MVP]
        - mvp@spam.guard. caspershouse.co m

        <steve_barker33 3@hotmail.com> wrote in message
        news:1137837606 .325372.54440@g 47g2000cwa.goog legroups.com...[color=blue]
        > Eric,
        >
        > Thanks for your reply Eric, and for your kind words! The link you have
        > included isn't the one I was thinking about, but it is similar. I've
        > had the code in my example running from server to client on a LAN,
        > using http:\\{IP}\etc ... addresses and http:\\{server name}\etc... It
        > seems random as to which machines it will and won't work on at the
        > moment! I've even had problems running the code on a single machine
        > acting as both client and server, which is strange. Do you think it is
        > due to restrictions imposed by IIS, IE, ASP.NET, .NET Framework or the
        > machine itself? (That's a lot of choices!)
        >
        > I suspect that my problems are security related as well; no doubt it'll
        > turn out to be a check box buried 10 menus deep that is missing a
        > check! If anyone can locate this check box (or whatever it is!) I'd be
        > very interested to hear what I need to do!
        >
        > Cheers,
        >
        > Steve.
        >[/color]


        Comment

        • steve_barker333@hotmail.com

          #5
          Re: Running Client Side C# Using ASP.NET

          Nicholas,

          Thanks for the advice! However, could you be a bit more specific about
          which settings I need to change please? I've had a look through the
          ..NET Configuration security settings, and there are a lot of options to
          play with!

          Steve.

          Comment

          • steve_barker333@hotmail.com

            #6
            Re: Running Client Side C# Using ASP.NET

            Nicholas,

            I don't know if you saw my last message, but I still can't get this
            thing working on my machine at home! Could you suggest which settings I
            look at changing please. Are we talking IIS, .NET Framework or
            something else?!

            Thanks a lot!

            Steve.

            Comment

            Working...