 |
| C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

September 19th, 2006, 12:57 AM
|
|
Registered User
|
|
Join Date: Jul 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Calling a method defined inside a .NET dll
I have created a Class Library and within the class library I have a Windows Form. I compiled this class library and got the dll. This dll is now embedded on a HTML page using:
<object id="ndcObj" classid="http://nh-rajen/ntest/NDCDemo.dll#NDCDemo.NDCDraw" height="356" width="367">
</object>
Now I need to call a method within this dll from javascript within the page, lets say I do it onClick of a button on the page as:
function ChangeText()
{
ndcObj.setText('Test Text');
}
This however does not work and I get the error that the object has no such defined properties or methods. How do I expose my method such that I can call it from outside of the dll. The current method definition for setText is:
public static void setText(string txtValue)
{
this.textBox1.Text = txtValue;
}
Please help me out..
Thanks in advance,
Cheers,
Rajen
|
|

September 19th, 2006, 06:39 PM
|
|
Authorized User
|
|
Join Date: Aug 2006
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Rajen,
First of all, the "static" constructor is not needed for your function inside the dll (windows control library).
Rewrite your function/method as follows:
public void setText(string txtValue)
{
this.textBox1.Text = txtValue;
}
After that, create a property inside your windows control library to set or get the textBox1 text within your HTML page as follows:
public string SetTextBoxText
{
get
{
this.setText("Your String");
return this.textBox1.Text;
}
set
{
this.textBox1.Text = value;
}
}
Now call your function with the javascript function below:
function SetObjectText
{
document.ndcObj.SetTextBoxText;
}
This should call your dll method setText() and change the object textbox1 text to "Your String". For me it works with .aspx pages.
[You must not re-invent the wheel but keep modifying the same wheel will not change the way of thinking.]
Regards,
.NETamateur
Electrical Engineer
|
|

September 20th, 2006, 02:24 PM
|
|
Authorized User
|
|
Join Date: Aug 2006
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Or less laborious and better to keep your code like it is, just rewrite your function without the static constructor and call it with javascript. I tried this with some existing code I have and it works.
Be aware that such controls only work in IE. You can better use Java to do this type of thing. Syntax is pretty much the same as C#.
Regards,
.NETamateur
Electrical Engineer
|
|

October 17th, 2006, 09:57 AM
|
|
Registered User
|
|
Join Date: Oct 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I am having a similar problem as rajen, and none of the above recommended solutions worked for me. If i am getting and setting properties that works fine but i get an error when i try to call the public method - "Object doesn't support this property or method"
[u]This is how i create my object:</u>
<OBJECT id="TCCControl" classid="../../Tools/ax_controls/MTAssemblies/TCC.dll#JNBS.CashDispenser.TCC.XMLRequest" VIEWASTEXT></OBJECT>
[u]Here is the call to the method in javascript :</u>
TCCControl.CreateXMLRequest();
[u]Here is a sample of the method in asp.net 2.0</u>
public void CreateXMLRequest()
{
FileInfo templateInfo = new FileInfo(destinationFile);
Guid guid = Guid.NewGuid();
string outputFileName = "\\q" + guid.ToString() + ".xml";
string outputFile = sourceFolder + outputFileName;
.......
}
Can someone please help me out here...i am not too sure what i am doing wrong
|
|

January 7th, 2008, 01:03 AM
|
|
Registered User
|
|
Join Date: Jan 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I have a .dll which needs to be invoked in javascript of asp.net application.
I have added the dll to the folder of the web application. And I have added the
following code to html as
<OBJECT id="myControl1" name="myControl1" width=288 height=72 classid=ActiveXDotNet.dll#ActiveXDotNet.UserContro l1 VIEWASTEXT>
</OBJECT>
and in javascript, i have tried to use a property of the UserControl1 as myControl1.propertyname... but I get an script error that
"myControl1 is undefined."
What are the steps that need to be followed to access or refer to .NET dll in javascript..
Do I need to register this dll, if so please mention the ways..
As well I have set the register for COM interop as true -- as well the AssemblyInfo -- comVisible to true , are these required ?
Thanks,
Sangeetha
|
|

January 7th, 2008, 04:04 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
Please start a new thread for a new question, you are much more likely to get an answer.
Try searching for RegAsm on Google. This is a tool that creates the necessary registry entries to use a .NET assembly as a COM DLL.
--
Joe ( Microsoft MVP - XML)
|
|
 |