我的代码有问题
这是我的母版页 HTML 代码
<%@ Master Language="VB" CodeFile="MasterPage.master.vb" Inherits="MasterPage" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<asp:ContentPlaceHolder id="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<div class="header" id="header">
<asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
<asp:HiddenField ID="param1" runat="server" />
<script type="text/javascript">
function alertMessage() {
var test = document.getElementById("param1").value;
alert(test);
}
</script>
</div>
</form>
</body>
</html>
这是我在子页面上调用隐藏字段的代码
Protected Button1_Click(sender as Object, e as EventArgs) Handles Button1.Click
Dim param1 As HiddenField = DirectCast(Page.Master.FindControl("param1"), HiddenField)
param1.Value = "Testing"
Dim csname1 As String = "ClientScript"
Dim csname2 As String = "alertMessage()"
Dim cstype As Type = Me.GetType()
Dim cs As ClientScriptManager = Page.ClientScript
If (Not cs.IsStartupScriptRegistered(cstype, csname1)) Then
cs.RegisterClientScriptBlock(cstype, csname1, csname2, True)
End If
cs.RegisterStartupScript(cstype, csname1, csname2, True)
End Sub
它使所述对象引用未设置为对象的实例
这是不断抛出错误的代码行
Dim param1 As HiddenField = DirectCast(Page.Master.FindControl("param1"), HiddenField)
谁能帮我???
感谢各种帮助
谢谢
试试这个
Dim param1 As HiddenField = Me.Page.Master.FindControl("param1")
然后将值分配给该控件。基本上,当您在之前使用隐藏的归档值时给它赋值这个错误来了。