User 58ea0aff73
20-11-2006 10:53:27
Dear Guys
Please Guid me, How to Use and work with marvin user controls in asp.net
Thanks & Regards
Sarma
ChemAxon 7c2d26e5cf
21-11-2006 09:32:50
User 58ea0aff73
26-11-2006 13:03:41
Hi Thomas...
I have seen this documentation on net. every thing i understud but I want to know bout Marvin APIs, how can i use it, in .Net i am a C# doveloper i don't know about Java... but now i can understnd something after i get into JChem. There i have founed some .net Examples.
I may come to you again. If want any help, please respond for my post
Thanks a lot for giving this replay...
Regards
Sarma
User 53790f777d
20-12-2006 19:47:21
I think I just had a similar question to the original poster. I just wanted to wrap the marvin sketcher in an ASP.NET user control and be able to set and get molecule information. That's it. So, I created this little ascx usercontrol in VB.NET that seems to do the right thing. I don't have a lot of experience writing ASP.NET usercontrols, so I wouldn't swear this adheres to any ASP.NET best practices, and there's lots in marvin that isn't handled here, but I thought others might find it useful as a starting point to roll their own.
thanks,
Chris
In my marvin.ascx page:
Code: |
<%@ Control Language="VB" AutoEventWireup="false" CodeFile="marvin.ascx.vb" Inherits="Applet.marvin" %>
<asp:HiddenField runat="server" ID="marvinmol" Value="" /> |
In my marvin.ascx.vb page:
Code: |
Namespace Applet
Partial Class marvin
Inherits System.Web.UI.UserControl
Private m_molecule As String
Private m_width As Integer = 300
Private m_height As Integer = 300
Private m_appletpath As String = "."
Private m_molformat As String = "mol"
Private m_debug As Boolean = False
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.Page.ClientScript.RegisterClientScriptInclude("marvininclude", ResolveClientUrl(m_appletpath & "/marvin.js"))
Me.Page.ClientScript.RegisterOnSubmitStatement(Me.GetType(), "marvinonsubmit", GetOnSubmitScript())
If m_appletpath = "" Then
Throw New Exception("AppletPath parameter must be defined.")
End If
End Sub
Public Property Debug() As Boolean
Get
Return m_debug
End Get
Set(ByVal value As Boolean)
m_debug = value
End Set
End Property
Public Property MoleculeFormat() As String
Get
Return m_molformat
End Get
Set(ByVal value As String)
m_molformat = value
End Set
End Property
Public Property AppletPath() As String
Get
Return m_appletpath
End Get
Set(ByVal value As String)
m_appletpath = value
End Set
End Property
Public Property Molecule() As String
Get
Return m_molecule
End Get
Set(ByVal value As String)
m_molecule = value
End Set
End Property
Public Property Width() As Integer
Get
Return m_width
End Get
Set(ByVal value As Integer)
m_width = value
End Set
End Property
Public Property Height() As Integer
Get
Return m_height
End Get
Set(ByVal value As Integer)
m_height = value
End Set
End Property
Protected Function GetOnloadScript() As String
Dim sb As New StringBuilder()
sb.Append("function() { var applet=" & GetMarvinAppletScriptRef() & ";" & vbCrLf)
sb.Append(" var hidden=" & GetHiddenElementScriptRef() & ";" & vbCrLf)
If m_debug Then sb.Append(" alert('Preloading molecule in " & m_molformat & " format: \n\n' + hidden.value)" & vbCrLf)
sb.Append(" applet.setMol(hidden.value, '" & m_molformat & "');" & vbCrLf)
sb.Append("}")
Return "window.attachEvent('onload', " & sb.ToString() & ");"
End Function
Protected Function GetOnSubmitScript() As String
Dim sb As New StringBuilder()
sb.Append(GetHiddenElementScriptRef() & ".value = " & GetMarvinAppletScriptRef() & ".getMol('" & m_molformat & "');")
If m_debug = True Then sb.Append("alert('Submitting molecule in " & m_molformat & " format:\n\n' + " & GetHiddenElementScriptRef() & ".value);")
Return sb.ToString()
End Function
Protected Function GetHiddenElementScriptRef() As String
Return "document.getElementById('" & marvinmol.ClientID & "')"
End Function
Protected Function GetMarvinAppletScriptRef() As String
Return "document.getElementsByName('" & ID & "')[0]"
End Function
Public Overrides Sub RenderControl(ByVal writer As System.Web.UI.HtmlTextWriter)
writer.AddAttribute("type", "text/javascript")
writer.RenderBeginTag(HtmlTextWriterTag.Script)
writer.Write("msketch_name = '" & ID & "';")
writer.Write("msketch_begin(""" & ResolveClientUrl(m_appletpath) & """, " & m_width & "," & m_height & ");")
writer.Write("msketch_end();")
writer.Write(GetOnloadScript())
writer.RenderEndTag()
MyBase.RenderControl(writer)
End Sub
End Class
End Namespace |
User 58ea0aff73
23-12-2006 03:18:20
Dear Chirs
This is very good practies for Asp.Net User controls. I have done this similar to this but not this muh... but it was improved me a lot.
I'm very Thankfull to your soupport.
Regards
Sarma