"风格"显示AJAX弹出窗口(vb.net)时出错

"Style" Error for Displaying AJAX Popup (vb.net)

本文关键字:quot vb net 出错 风格 显示 AJAX 窗口      更新时间:2023-09-26

当我尝试在VB中运行某些代码时遇到错误,我有一些VB代码告诉我的Griview添加一个标签,上面写着"插入电子邮件"在任何不包含电子邮件地址的行的最后一列中:

我还有一些代码,我想在点击Collumn中的标签后打开Ajax模式弹出框:

这是我的更新代码(仍然不起作用):

'----------------------------------------
For i As Integer = 0 To GridView1.Rows.Count - 1
If GridView1.Rows(i).Cells(9).Text = " " Then
Dim lbl As String
lbl = "Insert Email"
GridView1.Rows(i).Cells(9).Text = lbl
e.Row.Cells(9).Attributes("OnMouseOver") = "this.style.textDecoration='underline'; this.style.cursor='hand';"
e.Row.Cells(9).Attributes("OnMouseOut") = "this.style.textDecoration='none';"
e.Row.Cells(9).Attributes.Add("OnClick", "document.getElementById('" + deletePopup.ClientID + "').style.visibility= 'True'")
End If
Next
'----------------------------------------

错误是:

错误:无法获取未定义或空引用的属性"style"

我认为它指的是这条线:

e.Row.Cells(9).Attributes.Add("OnClick", "document.getElementById('deletePopup').Style.Visible = True'")


以下是应该打开的模式弹出窗口的ASPX代码:

    <div id="deletePopup" runat="server" class="modalPopup" 
    style="padding: 2px; width: 396px;" visible="false">
    <asp:HiddenField ID="ServiceID" runat="server" />
    <asp:HiddenField ID="HiddenDesc" runat="server" />
<asp:Label ID="Label4" runat="server" Text="Type in an Email:"></asp:Label>
<asp:TextBox ID="EmailTextBox1" runat="server" Height="22px" Width="370px"></asp:TextBox>
<asp:Button ID="UpdateEmailBtn" runat="server" Text="Update Email" />
<asp:Button ID="cancelButton" runat="server" Text="Cancel" />
</div>

我希望能得到一些帮助。提前谢谢。。。

我不太确定我输入的代码是否正确。。。

收到您的问题。

我看得出来,你已经使用了以下内容。

<div id="deletePopup" runat="server" class="modalPopup" style="padding: 2px; width: 396px;" visible="false">

使用visible=false时,将从DOM中删除deletePopup元素。

如果此属性为false,则不会呈现服务器控件。-MSDN

由于这在DOM中不存在,您将得到错误-Unable to get property 'style' of undefined。若要使用javascript使其可见,则需要仅使用客户端代码(css)使其隐藏,如下所示。

<div id="deletePopup" runat="server" class="modalPopup" style="padding: 2px; width: 396px;display:none;" >

并使用以下javascript使其可见。

e.Row.Cells(9).Attributes.Add("onclick", "document.getElementById('" + deletePopup.ClientID +"').style.display = 'block'")

附带说明:如果需要使用服务器端代码使其可见,可以使用deletePopup.Visible = True