locked
Winform user control hosted in IE: set property and call public member issues RRS feed

  • Question

  • User-2051989583 posted

    I have a Winform user control hosted in IE. the control and asp.net page wrote in .net 2.0.

    the control looks Ok on the asp.net page.

    the problem is on the page I have a button to trigger a javascript function. that javascript will pass a value to Winfom control by using property defined in winform user control. but that value never been set properly. also I try to call the control's public method from Javascript function. and I got Javascript error :" Object doesn't support the property or method".

    anyone got idea what's going on please help.

    here is my page

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" >

    <head runat="server">

    <title>Untitled Page</title>

    <script language="javascript" type="text/javascript">

    function Button1_onclick() {

    ct1.InputData="ABCD";

    alert(ct1.Calculate("fool"));

    }

    </script>

    </head>

    <body>

     

    <div><p>input&nbsp;

    <input id="Text1" type="text" /></p>

    <p>output<input id="Text2" type="text" /></p>

     

    <p>

    <input id="Button1" style="left: 0px; " type="button" value="button" language="javascript" onclick="return Button1_onclick()" />

    </p>

    </div>

    <p>

    <object id="ct1" ClassId="testcontrol3.dll#testcontrol.UserControl1" height="176" width="375" VIEWASTEXT>

    <param name="InputData" value="xyz" />

    </object></p>

    </body>

    here are the control class:

    using System;

    using System.Collections.Generic;

    using System.ComponentModel;

    using System.Drawing;

    using System.Data;

    using System.Text;

    using System.Windows.Forms;

    namespace testcontrol

    {

    interface api

    {

    string Calculate(string x);

    }

    public partial class UserControl1 : UserControl, api

    {

    public UserControl1():base()

    {

    InitializeComponent();

    }

    private string inputData="";

    public string InputData

    {

    get

    {

    return inputData;

    }

    set { inputData = value; }

    }

    private string outputData="";

    public string OutputData

    {

    get

    {

    return outputData;

    }

    set

    {

    outputData = value;

    }

    }

    public string Calculate(string x)

    {

    inputData=x;

    outputData = x.Length.ToString();

    return outputData;

    }

    private void button1_Click(object sender, EventArgs e)

    {

    txbInput.Text = inputData;

    txbOutput.Text = inputData + " test!";

    }

    }

    }

    Monday, August 28, 2006 6:02 PM

All replies

  • User4174898 posted

    read this

    http://dotnet.org.za/codingsanity/archive/2006/04/20/51710.aspx 

    and try this

    http://jb73.wordpress.com/2006/08/23/winforms-usercontrols-in-internet-explorer/

    :) 

    Wednesday, September 27, 2006 6:55 AM
  • User-271154005 posted

    [ComVisible(False)]

    Declare the above at the top of your class. This makes the methods and properties accessible via javascript


    Monday, October 26, 2009 9:58 AM