VB调用javascript实现删除前确认
<asp:GridView class="datatable" ID="GridViewAfd" runat="server" AllowSorting="True"
AutoGenerateDeleteButton="True" AutoGenerateEditButton="True"
AllowPaging="True" EnableViewState="False" EnableTheming="False" AutoGenerateColumns="False">
这是GridView,我想用的是btnSave.Attributes.Add(“onclick”,”Javascript:return confirm(‘Are you sure to save?’);”)这样的方法来弄,但是我找不到按键的对象名(例如btnSave),楼下贴出前台和后台的全部代码 --------------------编程问答-------------------- 前台代码:
<%@ Control language="vb" debug="true" Inherits="Modules.SLZKernDataBeheer.View" CodeFile="View.ascx.vb" AutoEventWireup="false" Explicit="True" %>--------------------编程问答-------------------- 后台执行删除调用的方法
<%@ Register TagPrefix="dnn" Namespace="DotNetNuke.UI.WebControls" Assembly="DotNetNuke.WebControls" %>
<asp:Label ID="debuglbl" runat="server" text=""/>
<asp:Panel ID="Panel1" runat="server" style="display:none; position:absolute; border:1px solid gray; border-left:#DDDDDD; border-top:#DDDDDD; background:#EEEEEE; width:270px; height: 70px; padding:6px; left: 288px; top: 8px;">
<asp:Label runat="server" ID="PanelLbl" Text="Kies"></asp:Label><br />
<asp:DropDownList ID="PanelList" runat="server" style="width:260px" EnableViewState="False"></asp:DropDownList><br />
<asp:HiddenField ID="PanelKey" runat="server" />
<asp:HiddenField ID="DelRelatieKey" runat="server" />
<asp:HiddenField ID="DelRelatieTable" runat="server" />
<asp:LinkButton ID="BtnAdd" runat="server" Text="Add"></asp:LinkButton>
<a href="#" onclick="toggle($('<%=Panel1.ClientID %>'))">Cancel</a></asp:Panel>
<strong>Gegevens: </strong>
<asp:DropDownList runat="server" ID="DataSelector" AutoPostBack="True"
EnableViewState="False">
<asp:ListItem>Vakgroepen</asp:ListItem>
<asp:ListItem>Afdelingen</asp:ListItem>
<asp:ListItem>Deelsites</asp:ListItem>
<asp:ListItem>Specialisten</asp:ListItem>
<asp:ListItem>Wachttijden</asp:ListItem>
<asp:ListItem>Spreekuren</asp:ListItem>
<asp:ListItem>Contactgegevens</asp:ListItem>
<asp:ListItem>Zoektrefwoorden</asp:ListItem>
<asp:ListItem>Links</asp:ListItem>
<asp:ListItem>Linkgroepen</asp:ListItem>
</asp:DropDownList>
<%If DataSelector.Text="Spreekuren" Then%>
<br/>Vakgroep: <asp:DropDownList runat="server" ID="Vakgroep"
AutoPostBack="True"></asp:DropDownList>
<asp:Button ID="btnExportPDF" runat="server" Text="PDF" /><br/>
Afdeling: <asp:DropDownList runat="server" ID="Afdeling"
AutoPostBack="True"/><br/>
<asp:Label ID="lblAfdeling" runat="server"></asp:Label>
<asp:GridView class="datatable" ID="GridViewEdit" runat="server" AllowSorting="False"
AutoGenerateDeleteButton="False" AutoGenerateEditButton="False"
AllowPaging="True" EnableViewState="False" EnableTheming="False" AutoGenerateColumns="False" ShowFooter="False">
<Columns>
<asp:TemplateField HeaderText="Specialist">
<ItemTemplate>
<asp:Label ID="Spe" runat="server"><%# Eval("Specialist") %></asp:Label>
<asp:HiddenField ID="HSpe" runat="server" Value='<%# Eval("Specialist") %>'/>
</ItemTemplate>
<FooterTemplate>
<asp:DropDownList runat="server" ID="FootSpecialist" AutoPostBack="true" class="footSpecialist"
DataTextField = "Achternaam" DataValueField = "ID" DataSource='<%#BindSpecialistData%>'>
</asp:DropDownList>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Ma">
<ItemTemplate>
<asp:DropDownList runat="server" ID="Ma" AutoPostBack="true">
<asp:ListItem Text="" Value=""/>
<asp:ListItem Text="o" Value="o"/>
<asp:ListItem Text="m" Value="m"/>
<asp:ListItem Text="om" Value="om"/>
</asp:DropDownList>
<asp:HiddenField ID="HW1" runat="server" Value='<%# Eval("w1") %>'/>
</ItemTemplate>
<FooterTemplate>
<asp:DropDownList runat="server" ID="FootMa" AutoPostBack="true">
<asp:ListItem Text="" Value=""/>
<asp:ListItem Text="o" Value="o"/>
<asp:ListItem Text="m" Value="m"/>
<asp:ListItem Text="om" Value="om"/>
</asp:DropDownList>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Di">
<ItemTemplate>
<asp:DropDownList runat="server" ID="Di" AutoPostBack="true">
<asp:ListItem Text="" Value=""/>
<asp:ListItem Text="o" Value="o"/>
<asp:ListItem Text="m" Value="m"/>
<asp:ListItem Text="om" Value="om"/>
</asp:DropDownList>
<asp:HiddenField ID="HW2" runat="server" Value='<%# Eval("w2") %>'/>
</ItemTemplate>
<FooterTemplate>
<asp:DropDownList runat="server" ID="FootDi" AutoPostBack="true">
<asp:ListItem Text="" Value=""/>
<asp:ListItem Text="o" Value="o"/>
<asp:ListItem Text="m" Value="m"/>
<asp:ListItem Text="om" Value="om"/>
</asp:DropDownList>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Wo">
<ItemTemplate>
<asp:DropDownList runat="server" ID="Wo" AutoPostBack="true">
<asp:ListItem Text="" Value=""/>
<asp:ListItem Text="o" Value="o"/>
<asp:ListItem Text="m" Value="m"/>
<asp:ListItem Text="om" Value="om"/>
</asp:DropDownList>
<asp:HiddenField ID="HW3" runat="server" Value='<%# Eval("w3") %>'/>
</ItemTemplate>
<FooterTemplate>
<asp:DropDownList runat="server" ID="FootWo" AutoPostBack="true">
<asp:ListItem Text="" Value=""/>
<asp:ListItem Text="o" Value="o"/>
<asp:ListItem Text="m" Value="m"/>
<asp:ListItem Text="om" Value="om"/>
</asp:DropDownList>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Do">
<ItemTemplate>
<asp:DropDownList runat="server" ID="Doo" AutoPostBack="true">
<asp:ListItem Text="" Value=""/>
<asp:ListItem Text="o" Value="o"/>
<asp:ListItem Text="m" Value="m"/>
<asp:ListItem Text="om" Value="om"/>
</asp:DropDownList>
<asp:HiddenField ID="HW4" runat="server" Value='<%# Eval("w4") %>'/>
</ItemTemplate>
<FooterTemplate>
<asp:DropDownList runat="server" ID="FootDoo" AutoPostBack="true">
<asp:ListItem Text="" Value=""/>
<asp:ListItem Text="o" Value="o"/>
<asp:ListItem Text="m" Value="m"/>
<asp:ListItem Text="om" Value="om"/>
</asp:DropDownList>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Vr">
<ItemTemplate>
<asp:DropDownList runat="server" ID="Vr" AutoPostBack="true">
<asp:ListItem Text="" Value=""/>
<asp:ListItem Text="o" Value="o"/>
<asp:ListItem Text="m" Value="m"/>
<asp:ListItem Text="om" Value="om"/>
</asp:DropDownList>
<asp:HiddenField ID="HW5" runat="server" Value='<%# Eval("w5") %>'/>
</ItemTemplate>
<FooterTemplate>
<asp:DropDownList runat="server" ID="FootVr" AutoPostBack="true">
<asp:ListItem Text="" Value=""/>
<asp:ListItem Text="o" Value="o"/>
<asp:ListItem Text="m" Value="m"/>
<asp:ListItem Text="om" Value="om"/>
</asp:DropDownList>
</FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<br />
<asp:Button runat="server" ID="NieuweBtn" Text="nieuwe arts" class="nieuweBtn"/>
<asp:Button runat="server" ID="EditBtn" Text="opslaan" class="editBtn" />
<%Else%>
Scope: <asp:DropDownList runat="server" ID="VGScope"
AutoPostBack="True" EnableViewState="False"></asp:DropDownList>
<br /><br />
Filter: <asp:TextBox ID="DataFilter" runat="server" AutoPostBack="True" EnableViewState="false"></asp:TextBox>
<br />
<br />
<asp:Label ID="lblItemCount" runat="server"></asp:Label>
<%If DataSelector.Text = "Afdelingen" Then%>
<asp:GridView class="datatable" ID="GridViewAfd" runat="server" AllowSorting="True"
AutoGenerateDeleteButton="True" AutoGenerateEditButton="True"
AllowPaging="True" EnableViewState="False" EnableTheming="False" AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField = "id" HeaderText = "id"/>
<asp:BoundField DataField = "afdeling" HeaderText = "Afdeling"/>
<asp:CheckBoxField DataField = "poli?" HeaderText = "Poli?" />
<asp:TemplateField HeaderText = "PrimVakGroep">
<EditItemTemplate>
<asp:DropDownList runat="server" ID="PrimVakGroep" AutoPostBack="false" >
</asp:DropDownList>
<asp:HiddenField ID="DefaultPrim" runat="server" Value='<%# Eval("PrimVakgroep") %>'/>
</EditItemTemplate>
<ItemTemplate>
<asp:Label runat="server" ID = "PrimText" Text='<%# Eval("PrimVakgroep") %>'></asp:Label>
<asp:HiddenField ID="DefaultPrimValue" runat="server" Value='<%# Eval("PrimVakgroep") %>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField ="" HeaderText = "Vakgroeprelaties" />
<asp:BoundField DataField ="" HeaderText = "Spreekuren" />
<asp:BoundField DataField ="" HeaderText = "Contactgegevens" />
<asp:BoundField DataField ="" HeaderText = "Wachttijden" />
<asp:BoundField DataField ="" HeaderText = "Specialisten" />
<asp:BoundField DataField ="" HeaderText = "Deelsites" />
</Columns>
</asp:GridView>
<%else %>
<asp:GridView class="datatable" ID="GridView" runat="server" AllowSorting="True"
AutoGenerateDeleteButton="True" AutoGenerateEditButton="True"
AllowPaging="True" EnableViewState="False" EnableTheming="False">
</asp:GridView>
<%End If%>
<br />
<asp:Button runat="server" ID="AddBtn" Text="Voeg een vakgroep toe" />
<%End If%>
<br />
<br />
# items per pagina: <asp:TextBox ID="ItemsPerPage" runat="server" AutoPostBack="True" Text="10" Width="30"></asp:TextBox>
<br />
Preview # relaties: <asp:TextBox ID="RelatiePreview" runat="server" AutoPostBack="True" Text="0" Width="30"></asp:TextBox>
<br />
<br />
<%--<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="false"/>--%>
Sub DeleteRelation()--------------------编程问答-------------------- 这个工程是用DNN框架做的,临时安排我做这个项目,我不是学VB的所以对VB的语法和结构不了解,各位大虾帮帮忙哈 --------------------编程问答-------------------- ((button)findcontrol("id")).attribute.add("click","return confirm('确认删除?');"); --------------------编程问答--------------------
If Not DelRelatieKey.Value = "" Then
Dim cn As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("SLZData").ConnectionString)
Dim cmd As SqlCommand = New SqlCommand("", cn)
cmd.CommandText = "DELETE FROM " & DelRelatieTable.Value & " WHERE ID=" & DelRelatieKey.Value
DelRelatieKey.Value = ""
DelRelatieTable.Value = ""
cn.Open()
cmd.ExecuteNonQuery()
cn.Close()
GetMetaData()
End If
End Sub
大哥能不能详细一点啊,((button)findcontrol("id"))这个是强制转换控件为button?头晕啊…… --------------------编程问答--------------------
还是说findcontrol("id")是一个通过控件id找控件的方法? --------------------编程问答-------------------- 别沉啊,有同样想知道的童鞋一起顶起来啊
补充:.NET技术 , ASP.NET