O
o0JoeCool0o
I am trying to create a User Control, that will be a message box with
input options
if I call okconf.visible = true in the page load of the user control it
works fine, but if i then try to call it later by calling the user
controls alert method i get a reference null error.
heres the class code
Public Class AlertBox1
Inherits System.Web.UI.UserControl
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
End Sub
Protected WithEvents btnOk As System.Web.UI.WebControls.Button
Protected WithEvents okconf As
System.Web.UI.HtmlControls.HtmlGenericControl
Protected WithEvents oktitle As
System.Web.UI.HtmlControls.HtmlGenericControl
Protected WithEvents okmsg As
System.Web.UI.HtmlControls.HtmlGenericControl
Protected WithEvents btnYes As System.Web.UI.WebControls.Button
Protected WithEvents btnNo As System.Web.UI.WebControls.Button
'NOTE: The following placeholder declaration is required by the Web
Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
okconf.Visible = False
End Sub
Public Enum msgType
okMsg
YesNo
End Enum
Public Sub alert(ByVal MsgText As String, ByVal msgTitle As String,
Optional ByVal OKMethod As String = "", Optional ByVal AlertType As
msgType = msgType.okMsg, Optional ByVal YesMethod As String = "",
Optional ByVal NoMethod As String = "")
Select Case AlertType
Case Is = msgType.okMsg
okconf.Visible = True
btnYes.Visible = False
btnNo.Visible = False
btnOk.Visible = True
Session("OKProc") = OKMethod
okmsg.InnerHtml = MsgText
oktitle.InnerHtml = msgTitle
okconf.Style.Item("left") = 300
okconf.Style.Item("TOP") = 300
'focus ok button
Page.RegisterStartupScript("CallSetFocus", "<SCRIPT
language=javascript>GetElementByName('btnOk').focus();</SCRIPT>")
Case Is = msgType.YesNo
okconf.Visible = True
btnYes.Visible = True
btnNo.Visible = True
btnOk.Visible = False
Session("YProc") = YesMethod
Session("NProc") = NoMethod
Session("YNAns") = ""
okmsg.InnerHtml = MsgText
oktitle.InnerHtml = msgTitle
okconf.Style.Item("left") = 300
okconf.Style.Item("TOP") = 200
'Focus Yes Button
Page.RegisterStartupScript("CallSetFocus", "<SCRIPT
language=javascript>GetElementByName('btnYes').focus();</SCRIPT>")
End Select
End Sub
End Class
heres the code behind for the main page
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Dim alert As New AlertBox1
alert.alert("a message in the box", "a msg title", ,
AlertBox1.msgType.okMsg)
End Sub
so it crashes on the user control code behind when it tries to set
okconf.visible to true
please help!
input options
if I call okconf.visible = true in the page load of the user control it
works fine, but if i then try to call it later by calling the user
controls alert method i get a reference null error.
heres the class code
Public Class AlertBox1
Inherits System.Web.UI.UserControl
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
End Sub
Protected WithEvents btnOk As System.Web.UI.WebControls.Button
Protected WithEvents okconf As
System.Web.UI.HtmlControls.HtmlGenericControl
Protected WithEvents oktitle As
System.Web.UI.HtmlControls.HtmlGenericControl
Protected WithEvents okmsg As
System.Web.UI.HtmlControls.HtmlGenericControl
Protected WithEvents btnYes As System.Web.UI.WebControls.Button
Protected WithEvents btnNo As System.Web.UI.WebControls.Button
'NOTE: The following placeholder declaration is required by the Web
Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
okconf.Visible = False
End Sub
Public Enum msgType
okMsg
YesNo
End Enum
Public Sub alert(ByVal MsgText As String, ByVal msgTitle As String,
Optional ByVal OKMethod As String = "", Optional ByVal AlertType As
msgType = msgType.okMsg, Optional ByVal YesMethod As String = "",
Optional ByVal NoMethod As String = "")
Select Case AlertType
Case Is = msgType.okMsg
okconf.Visible = True
btnYes.Visible = False
btnNo.Visible = False
btnOk.Visible = True
Session("OKProc") = OKMethod
okmsg.InnerHtml = MsgText
oktitle.InnerHtml = msgTitle
okconf.Style.Item("left") = 300
okconf.Style.Item("TOP") = 300
'focus ok button
Page.RegisterStartupScript("CallSetFocus", "<SCRIPT
language=javascript>GetElementByName('btnOk').focus();</SCRIPT>")
Case Is = msgType.YesNo
okconf.Visible = True
btnYes.Visible = True
btnNo.Visible = True
btnOk.Visible = False
Session("YProc") = YesMethod
Session("NProc") = NoMethod
Session("YNAns") = ""
okmsg.InnerHtml = MsgText
oktitle.InnerHtml = msgTitle
okconf.Style.Item("left") = 300
okconf.Style.Item("TOP") = 200
'Focus Yes Button
Page.RegisterStartupScript("CallSetFocus", "<SCRIPT
language=javascript>GetElementByName('btnYes').focus();</SCRIPT>")
End Select
End Sub
End Class
heres the code behind for the main page
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Dim alert As New AlertBox1
alert.alert("a message in the box", "a msg title", ,
AlertBox1.msgType.okMsg)
End Sub
so it crashes on the user control code behind when it tries to set
okconf.visible to true
please help!