Need help exdending custom control. THANK YOU!!!

  • Thread starter Daniel Walzenbach
  • Start date
D

Daniel Walzenbach

Hi,



I created the following custom control to open a form in a new window. All this control does is to write a JavaScript link. Additionally I'd like to react on a MouseClick made on the control. How can I do this?





' This is the control by now...

' ***********************************************************************

Imports System.ComponentModel

Imports System.Web.UI

Imports System.Text

Imports System.Web.UI.WebControls



<DefaultProperty("Text"), ToolboxData("<{0}:popUpWindow runat=server></{0}:popUpWindow>")> Public Class PopUpWindow



Inherits System.Web.UI.WebControls.WebControl



Public EditMode As Boolean = False

Public Scrollbars As Boolean = False

Public Menubar As Boolean = False

Public Modal As Boolean = False

Public Locationbar As Boolean = False

Public Resizable As Boolean = False

Public Statusbar As Boolean = False

Public Fullscreen As Boolean = False

Public Top As Unit = New Unit()

Public Left As Unit = New Unit()

Public Text As String = ""

Public ImageUrl As String = ""

Public AlternateText As String = ""







'**********************navigate url als proproperty***********************

<Bindable(True), Category("Appearance"), DefaultValue("")> Property NavigateUrl() As String

Get

Dim _obj As Object = viewstate("NavigateUrl")

If _obj Is System.DBNull.Value Then

Return String.Empty

Else

Return _obj.ToString

End If

End Get



Set(ByVal Value As String)

viewstate("NavigateUrl") = Value

End Set

End Property



Protected Overrides Sub Render(ByVal output As System.Web.UI.HtmlTextWriter)

If ImageUrl <> String.Empty Then

Text = "<img src='" + ImageUrl + "' alt='" + AlternateText + "' border='0'>" + Text



End If

output.Write("<a href='javascript:popUp_" + Me.ClientID + "()'>" + Text + "</a>")

End Sub



Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)

'********hier string fuer options bauen***************************

Dim options As StringBuilder = New StringBuilder()

Dim myString As StringBuilder = New StringBuilder("<script language='javascript'>")



If Fullscreen Then

options.Append("Fullscreen=yes, ")

Else

options.Append("Fullscreen=no, ")

End If



If Scrollbars Then

options.Append("Scrollbars=yes, ")

Else

options.Append("Scrollbars=no, ")

End If



If Menubar Then

options.Append("Menubar=yes, ")

Else

options.Append("Menubar=no, ")

End If



If Locationbar Then

options.Append("Locationbar=yes, ")

Else

options.Append("Locationbar=no, ")

End If



If Resizable Then

options.Append("Resizable=yes, ")

Else

options.Append("Resizable=no, ")

End If



If Statusbar Then

options.Append("Status=yes ")

Else

options.Append("Status=no ")

End If



If Not Left.IsEmpty Then

options.Append("left=" + Left.ToString + ", ")

End If



If Not Top.IsEmpty Then

options.Append("top=" + Top.ToString + ", ")

End If



If Not Width.IsEmpty Then

options.Append("width=" + Width.ToString + ", ")

End If



If Not Height.IsEmpty Then

options.Append("height=" + Height.ToString)

End If



myString.Append("function PopUp_" + Me.ClientID + "(){")

If Modal Then

myString.Append(" window.showModalDialog('" + viewstate("NavigateUrl") + "','','" + options.ToString + "')")

Else

myString.Append(" window.open('" + viewstate("NavigateUrl") + "','','" + options.ToString + "')")

End If



myString.Append("}</script")

myString.Append(">")

Page.RegisterClientScriptBlock("PopUp_" + Me.ClientID, myString.ToString)



End Sub

End Class


Thanks a lot for your help.
Best regards

Daniel Walzenbach

P.S. If you need to contact me simply remove ".NOSPAM" from my email address.
 
J

Jacob Yang [MSFT]

Hi Daniel,

Do you remember me? I am glad to work with you again :)

I am sorry if there is any misunderstanding.

If I didn't misunderstand you, you want to trigger the client-side
onmousedown event when the link inside the custom control was clicked. If
it is the case, you can override the OnPreRender event inside the custom
control, where you can use the Page.RegisterClientScriptBlock() method to
register the client-side javascript block to be invoked when mouse was
clicked on the link in the custom control.

If I have misunderstood your concern, please feel free to let me know.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
R

Rajesh.V

If You mean, on click the control also has to postback and you wud like a public event. If this is the case then you wud have to implement the interface
IPostBackEventHandler

Hi,



I created the following custom control to open a form in a new window. All this control does is to write a JavaScript link. Additionally I'd like to react on a MouseClick made on the control. How can I do this?





' This is the control by now...

' ***********************************************************************

Imports System.ComponentModel

Imports System.Web.UI

Imports System.Text

Imports System.Web.UI.WebControls



<DefaultProperty("Text"), ToolboxData("<{0}:popUpWindow runat=server></{0}:popUpWindow>")> Public Class PopUpWindow



Inherits System.Web.UI.WebControls.WebControl



Public EditMode As Boolean = False

Public Scrollbars As Boolean = False

Public Menubar As Boolean = False

Public Modal As Boolean = False

Public Locationbar As Boolean = False

Public Resizable As Boolean = False

Public Statusbar As Boolean = False

Public Fullscreen As Boolean = False

Public Top As Unit = New Unit()

Public Left As Unit = New Unit()

Public Text As String = ""

Public ImageUrl As String = ""

Public AlternateText As String = ""







'**********************navigate url als proproperty***********************

<Bindable(True), Category("Appearance"), DefaultValue("")> Property NavigateUrl() As String

Get

Dim _obj As Object = viewstate("NavigateUrl")

If _obj Is System.DBNull.Value Then

Return String.Empty

Else

Return _obj.ToString

End If

End Get



Set(ByVal Value As String)

viewstate("NavigateUrl") = Value

End Set

End Property



Protected Overrides Sub Render(ByVal output As System.Web.UI.HtmlTextWriter)

If ImageUrl <> String.Empty Then

Text = "<img src='" + ImageUrl + "' alt='" + AlternateText + "' border='0'>" + Text



End If

output.Write("<a href='javascript:popUp_" + Me.ClientID + "()'>" + Text + "</a>")

End Sub



Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)

'********hier string fuer options bauen***************************

Dim options As StringBuilder = New StringBuilder()

Dim myString As StringBuilder = New StringBuilder("<script language='javascript'>")



If Fullscreen Then

options.Append("Fullscreen=yes, ")

Else

options.Append("Fullscreen=no, ")

End If



If Scrollbars Then

options.Append("Scrollbars=yes, ")

Else

options.Append("Scrollbars=no, ")

End If



If Menubar Then

options.Append("Menubar=yes, ")

Else

options.Append("Menubar=no, ")

End If



If Locationbar Then

options.Append("Locationbar=yes, ")

Else

options.Append("Locationbar=no, ")

End If



If Resizable Then

options.Append("Resizable=yes, ")

Else

options.Append("Resizable=no, ")

End If



If Statusbar Then

options.Append("Status=yes ")

Else

options.Append("Status=no ")

End If



If Not Left.IsEmpty Then

options.Append("left=" + Left.ToString + ", ")

End If



If Not Top.IsEmpty Then

options.Append("top=" + Top.ToString + ", ")

End If



If Not Width.IsEmpty Then

options.Append("width=" + Width.ToString + ", ")

End If



If Not Height.IsEmpty Then

options.Append("height=" + Height.ToString)

End If



myString.Append("function PopUp_" + Me.ClientID + "(){")

If Modal Then

myString.Append(" window.showModalDialog('" + viewstate("NavigateUrl") + "','','" + options.ToString + "')")

Else

myString.Append(" window.open('" + viewstate("NavigateUrl") + "','','" + options.ToString + "')")

End If



myString.Append("}</script")

myString.Append(">")

Page.RegisterClientScriptBlock("PopUp_" + Me.ClientID, myString.ToString)



End Sub

End Class


Thanks a lot for your help.
Best regards

Daniel Walzenbach

P.S. If you need to contact me simply remove ".NOSPAM" from my email address.
 
D

Daniel Walzenbach

Thank you Jacob & Rajesh for your help. I'm confident to solve my probmen now. Thanks again!

Daniel

If You mean, on click the control also has to postback and you wud like a public event. If this is the case then you wud have to implement the interface
IPostBackEventHandler

Hi,



I created the following custom control to open a form in a new window. All this control does is to write a JavaScript link. Additionally I'd like to react on a MouseClick made on the control. How can I do this?





' This is the control by now...

' ***********************************************************************

Imports System.ComponentModel

Imports System.Web.UI

Imports System.Text

Imports System.Web.UI.WebControls



<DefaultProperty("Text"), ToolboxData("<{0}:popUpWindow runat=server></{0}:popUpWindow>")> Public Class PopUpWindow



Inherits System.Web.UI.WebControls.WebControl



Public EditMode As Boolean = False

Public Scrollbars As Boolean = False

Public Menubar As Boolean = False

Public Modal As Boolean = False

Public Locationbar As Boolean = False

Public Resizable As Boolean = False

Public Statusbar As Boolean = False

Public Fullscreen As Boolean = False

Public Top As Unit = New Unit()

Public Left As Unit = New Unit()

Public Text As String = ""

Public ImageUrl As String = ""

Public AlternateText As String = ""







'**********************navigate url als proproperty***********************

<Bindable(True), Category("Appearance"), DefaultValue("")> Property NavigateUrl() As String

Get

Dim _obj As Object = viewstate("NavigateUrl")

If _obj Is System.DBNull.Value Then

Return String.Empty

Else

Return _obj.ToString

End If

End Get



Set(ByVal Value As String)

viewstate("NavigateUrl") = Value

End Set

End Property



Protected Overrides Sub Render(ByVal output As System.Web.UI.HtmlTextWriter)

If ImageUrl <> String.Empty Then

Text = "<img src='" + ImageUrl + "' alt='" + AlternateText + "' border='0'>" + Text



End If

output.Write("<a href='javascript:popUp_" + Me.ClientID + "()'>" + Text + "</a>")

End Sub



Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)

'********hier string fuer options bauen***************************

Dim options As StringBuilder = New StringBuilder()

Dim myString As StringBuilder = New StringBuilder("<script language='javascript'>")



If Fullscreen Then

options.Append("Fullscreen=yes, ")

Else

options.Append("Fullscreen=no, ")

End If



If Scrollbars Then

options.Append("Scrollbars=yes, ")

Else

options.Append("Scrollbars=no, ")

End If



If Menubar Then

options.Append("Menubar=yes, ")

Else

options.Append("Menubar=no, ")

End If



If Locationbar Then

options.Append("Locationbar=yes, ")

Else

options.Append("Locationbar=no, ")

End If



If Resizable Then

options.Append("Resizable=yes, ")

Else

options.Append("Resizable=no, ")

End If



If Statusbar Then

options.Append("Status=yes ")

Else

options.Append("Status=no ")

End If



If Not Left.IsEmpty Then

options.Append("left=" + Left.ToString + ", ")

End If



If Not Top.IsEmpty Then

options.Append("top=" + Top.ToString + ", ")

End If



If Not Width.IsEmpty Then

options.Append("width=" + Width.ToString + ", ")

End If



If Not Height.IsEmpty Then

options.Append("height=" + Height.ToString)

End If



myString.Append("function PopUp_" + Me.ClientID + "(){")

If Modal Then

myString.Append(" window.showModalDialog('" + viewstate("NavigateUrl") + "','','" + options.ToString + "')")

Else

myString.Append(" window.open('" + viewstate("NavigateUrl") + "','','" + options.ToString + "')")

End If



myString.Append("}</script")

myString.Append(">")

Page.RegisterClientScriptBlock("PopUp_" + Me.ClientID, myString.ToString)



End Sub

End Class


Thanks a lot for your help.
Best regards

Daniel Walzenbach

P.S. If you need to contact me simply remove ".NOSPAM" from my email address.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top