【问题标题】:"Style" Error for Displaying AJAX Popup (vb.net)显示 AJAX 弹出窗口的“样式”错误 (vb.net)
【发布时间】:2014-12-22 13:33:26
【问题描述】:

当我尝试在 VB 中运行一些代码时出现错误,我有一些 VB 代码告诉我的 Griview 添加一个标有“插入电子邮件”的标签 在不包含电子邮件地址的任何行中的最后一列中:

我还有一些代码,一旦单击列中的标签,我想打开一个 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

'----------------------------------------

错误是:

错误:无法获取未定义或空引用的属性“样式”

我认为是指这一行:

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>

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

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

【问题讨论】:

  • 您很可能已经检查过了。但是您确定确实存在 id 为“deletePopup”的元素吗?
  • 您应该尝试 document.getElementById("deletePopup").style.display = "none" ,但在此之前请检查页面中是否有 deletePopup 元素。
  • 属性区分大小写 ;)
  • 然后用deletePopup.ClientID代替deletePopup
  • 是的,它被正确引用,我只是不明白为什么它不起作用。 @ArindamNayak

标签: javascript asp.net ajax vb.net gridview


【解决方案1】:

有你的问题。

我看出来了,你用了following。

&lt;div id="deletePopup" runat="server" class="modalPopup" style="padding: 2px; width: 396px;" visible="false"&gt;

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

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

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

&lt;div id="deletePopup" runat="server" class="modalPopup" style="padding: 2px; width: 396px;display:none;" &gt;

并使用以下 javascript 使其可见。

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-14
    • 2022-01-21
    • 1970-01-01
    相关资源
    最近更新 更多