我有一个C#code-背后一个asp页面。我想有code-背后显示,如果一个GridView对象的选择,指数没有选择确认或取消改变的警报。在code表示,如果确认或选择取消正在检测,但永远不会显示我的消息。在'Alert.Showcode,从借来的:archive.devnewz/devnewz-3-20061129JavaScriptAlertShowmessagefromASPNET$c$cbehind.html
从在Page_Load(测试时Alert.show工作得很好),例如,而不是在我的selected_index_changed方法。知道为什么吗?或许具有Alert.Show()是如何实现的呢?
如果(ChangeAttemptedId&安培;&安培;!IsSavedId){ Alert.Show(调度作业保存,但你忘了点击确认或取消!));}ASP.NET code:
< ASP:表ID =表1=服务器的CssClass =DefaultTable> < ASP:的TableRow =服务器> < ASP:TableCell的=服务器WIDTH =50%VerticalAlign =评出的HorizontalAlign =左> < ASP:的UpdatePanel ID =detailsUP=服务器的UpdateMode =始终ChildrenAsTriggers =真> <&的ContentTemplate GT; <! - < ASP:标签ID =LABEL1=服务器文本=汽车调度的CssClass =DefaultLabel>< / ASP:标签> < ASP:DropDownList的ID =CarsDDL=服务器的DataSourceID =VehiclesEDS的DataMember =CarNumDataTextField =CarNumAppendDataBoundItems =真字体粗体=真> < ASP:列表项选择=真正的文本= - >< / ASP:ListItem的> < / ASP:DropDownList的> - > < ASP:DetailsView控件ID =RideToAssignDV=服务器HEIGHT =400像素 WIDTH =400像素AutoGenerateRows =FALSE 背景色=白BORDERCOLOR =#999999边框=无边框宽度=1像素 CELLPADDING =3网格=垂直> < AlternatingRowStyle背景色=#DCDCDC/> < EditRowStyle背景色=#008A8CFONT-粗体=真前景色=白/> LT&;&领域GT; < ASP:BoundField的数据字段=AssignedCar的HeaderText =汽车 SORTEX pression =AssignedCarNullDisplayText =---/> < ASP:BoundField的数据字段=名称的HeaderText =姓名 SORTEX pression =名称NullDisplayText =---/> < ASP:BoundField的数据字段=手机的HeaderText =手机 SORTEX pression =电话NullDisplayText =---/> < ASP:BoundField的数据字段=NumPatrons的HeaderText =大小 SORTEX pression =NumPatronsNullDisplayText =---/> < ASP:BoundField的数据字段=PickupAddress的HeaderText =取件地址 SORTEX pression =PickupAddressNullDisplayText =---/> < ASP:BoundField的数据字段=DropoffAddress的HeaderText =下车地址 SORTEX pression =DropoffAddressNullDisplayText =---/> < ASP:BoundField的数据字段=CreatedBy的HeaderText =创建者 SORTEX pression =CreatedByNullDisplayText =---/> < ASP:BoundField的数据字段=TIMEOFCALL的HeaderText =通话时间 SORTEX pression =TIMEOFCALL只读=真NullDisplayText =---/> < /场> < FooterStyle背景色=#CCCCCC前景色=黑色边框=插图BORDERCOLOR =#C6940DHorizontalAlign =中心HEIGHT =25像素/> < FooterTemplate> < ASP:按钮的ID =confirmButton=服务器文本=确认前景色=绿色HorizontalAlign =中心的OnClick =confirmButton_Click/> < ASP:按钮的ID =cancelButton=服务器文本=取消前景色=红HorizontalAlign =中心 的OnClick =cancelButton_Click的OnClientClick =displayTopTen(); /> < / FooterTemplate> < HeaderStyle背景色=#004812FONT-粗体=真/> < PagerStyle背景色=#999999前景色=黑/> < RowStyle的BackColor =#EEEEEE前景色=黑/> < / ASP:DetailsView控件> < /&的ContentTemplate GT; < / ASP:的UpdatePanel> < / ASP:TableCell的> < ASP:TableCell的=服务器WIDTH =50%> < ASP:的UpdatePanel ID =MapUp活动=服务器的UpdateMode =条件> <&的ContentTemplate GT; < DIV ID =map_canvas的风格=高度:400像素;宽度:400像素;>< / DIV> < /&的ContentTemplate GT; < / ASP:的UpdatePanel> < / ASP:TableCell的> < / ASP:&的TableRow GT;< / ASP:表>< BR />< ASP:标签ID =GV_Label1=服务器文本=汽车调度的CssClass =DefaultLabel>< / ASP:标签>< ASP:的UpdatePanel ID =SelectCarUP=服务器的UpdateMode =条件> <&的ContentTemplate GT; < ASP:GridView控件ID =VehiclesGridView=服务器AllowPaging =真 AllowSorting =真的DataSourceID =VehiclesEDS的AutoGenerateColumns =FALSE onselectedindexchanged =VehiclesGridView_SelectedIndexChanged 背景色=白BORDERCOLOR =#999999边框=无边框宽度=1像素 CELLPADDING =3网格=垂直ShowHeaderWhenEmpty =真的AutoPostBack =真> < AlternatingRowStyle背景色=#DCDCDC/> <柱体和GT; < ASP:的TemplateField ShowHeader =FALSE> <&ItemTemplate中GT; < ASP:LinkButton的ID =GVSelectButton=服务器的CausesValidation =FALSE 的CommandName =选择文本=选择>< / ASP:LinkButton的> < / ItemTemplate中> < / ASP:的TemplateField> < ASP:BoundField的数据字段=CarNum的HeaderText =汽车只读=真 SORTEX pression =CarNum/> < ASP:BoundField的数据字段=CurrPassengers的HeaderText =乘客 只读=真SORTEX pression =CurrPassengers/> < ASP:BoundField的数据字段=MaxPassengers的HeaderText =容量只读=真 SORTEX pression =MaxPassengers/> < ASP:BoundField的数据字段=状态的HeaderText =状态只读=真 SORTEX pression =状态/> < ASP:BoundField的数据字段=StartAdd的HeaderText =提货地址 只读=真SORTEX pression =StartAdd/> < ASP:BoundField的数据字段=EndAdd的HeaderText =下车地址 只读=真SORTEX pression =EndAdd/> < ASP:BoundField的数据字段=AvgRideTime的HeaderText =平均换乘时间 只读=真SORTEX pression =AvgRideTime/> < /专栏> < FooterStyle背景色=#CCCCCC前景色=黑/> < HeaderStyle背景色=#004812FONT-粗体=真前景色=白/> < PagerStyle背景色=#999999前景色=黑HorizontalAlign =中心/> < RowStyle的BackColor =#EEEEEE前景色=黑/> < SelectedRowStyle背景色=#C6940DFONT-粗体=真前景色=白/> < SortedAscendingCellStyle背景色=#F1F1F1/> < SortedAscendingHeaderStyle背景色=#C6940D/> < SortedDescendingCellStyle背景色=#CAC9C9/> < SortedDescendingHeaderStyle背景色=#9F770B/> < / ASP:GridView的> < /&的ContentTemplate GT;< / ASP:的UpdatePanel>解决方案 说明
假设我明白你的问题。
您可以使用的ScriptManager 来显示的JavaScript 警报消息。
示例 保护无效的Page_Load(对象发件人,EventArgs的发送){ ScriptManager.RegisterStartupScript(this.Page,this.Page.GetType(), ERR_MSG 警报('派遣作业保存,但你忘了点击确认或取消!)');, 真正);}更多信息
- MSDN - ClientScriptManager.RegisterStartupScript方法
I have an asp page with a c# code-behind. I am trying to have the code-behind display an 'alert' if the selected-index of a gridview object is changed without selecting 'confirm' or 'cancel'. The code for detecting if confirm or cancel was selected is working, however my message is never displayed. The 'Alert.Show" code was borrowed from: archive.devnewz/devnewz-3-20061129JavaScriptAlertShowmessagefromASPNETCodebehind.html .
Alert.show works just fine when tested from the page_load(), for example, but not in my selected_index_changed method. Any idea why? Perhaps having to do with how Alert.Show() is implemented?
if (ChangeAttemptedId && !IsSavedId) { Alert.Show("Dispatch assignment saved, but you forgot to click Confirm or Cancel!)"); }ASP.NET CODE:
<asp:Table ID="Table1" runat="server" CssClass="DefaultTable"> <asp:TableRow runat="server"> <asp:TableCell runat="server" Width="50%" VerticalAlign="Top" HorizontalAlign="Left"> <asp:UpdatePanel ID="detailsUP" runat="server" UpdateMode="Always" ChildrenAsTriggers="True"> <ContentTemplate> <!-- <asp:Label ID="label1" runat="server" Text="Car To Dispatch: " CssClass="DefaultLabel"></asp:Label> <asp:DropDownList ID="CarsDDL" runat="server" DataSourceID="VehiclesEDS" DataMember="CarNum" DataTextField="CarNum" AppendDataBoundItems="True" Font-Bold="True"> <asp:ListItem Selected="True" Text="-"></asp:ListItem> </asp:DropDownList> --> <asp:DetailsView ID="RideToAssignDV" runat="server" Height="400px" Width="400px" AutoGenerateRows="False" BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Vertical"> <AlternatingRowStyle BackColor="#DCDCDC" /> <EditRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" /> <Fields> <asp:BoundField DataField="AssignedCar" HeaderText="Car" SortExpression="AssignedCar" NullDisplayText="---" /> <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" NullDisplayText="---" /> <asp:BoundField DataField="Phone" HeaderText="Phone" SortExpression="Phone" NullDisplayText="---" /> <asp:BoundField DataField="NumPatrons" HeaderText="Size" SortExpression="NumPatrons" NullDisplayText="---" /> <asp:BoundField DataField="PickupAddress" HeaderText="Pickup Address" SortExpression="PickupAddress" NullDisplayText="---" /> <asp:BoundField DataField="DropoffAddress" HeaderText="Drop-Off Address" SortExpression="DropoffAddress" NullDisplayText="---" /> <asp:BoundField DataField="CreatedBy" HeaderText="Created By" SortExpression="CreatedBy" NullDisplayText="---" /> <asp:BoundField DataField="TimeOfCall" HeaderText="Call Time" SortExpression="TimeOfCall" ReadOnly="True" NullDisplayText="---" /> </Fields> <FooterStyle BackColor="#CCCCCC" ForeColor="Black" BorderStyle="Inset" BorderColor="#C6940D" HorizontalAlign="Center" Height="25px" /> <FooterTemplate> <asp:Button ID="confirmButton" runat="server" Text="Confirm" ForeColor="Green" HorizontalAlign="Center" OnClick="confirmButton_Click"/> <asp:Button ID="cancelButton" runat="server" Text="Cancel" ForeColor="Red" HorizontalAlign="Center" OnClick="cancelButton_Click" OnClientClick="displayTopTen();" /> </FooterTemplate> <HeaderStyle BackColor="#004812" Font-Bold="True" /> <PagerStyle BackColor="#999999" ForeColor="Black" /> <RowStyle BackColor="#EEEEEE" ForeColor="Black" /> </asp:DetailsView> </ContentTemplate> </asp:UpdatePanel> </asp:TableCell> <asp:TableCell runat="server" Width="50%"> <asp:UpdatePanel ID="mapUP" runat="server" UpdateMode="Conditional"> <ContentTemplate> <div id="map_canvas" style="height: 400px; width:400px;"></div> </ContentTemplate> </asp:UpdatePanel> </asp:TableCell> </asp:TableRow> </asp:Table> <br /> <asp:Label ID="GV_Label1" runat="server" Text="Car To Dispatch: " CssClass="DefaultLabel"></asp:Label> <asp:UpdatePanel ID="SelectCarUP" runat="server" UpdateMode="Conditional"> <ContentTemplate> <asp:GridView ID="VehiclesGridView" runat="server" AllowPaging="True" AllowSorting="True" DataSourceID="VehiclesEDS" AutoGenerateColumns="False" onselectedindexchanged="VehiclesGridView_SelectedIndexChanged" BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Vertical" ShowHeaderWhenEmpty="True" AutoPostBack="True"> <AlternatingRowStyle BackColor="#DCDCDC" /> <Columns> <asp:TemplateField ShowHeader="False"> <ItemTemplate> <asp:LinkButton ID="GVSelectButton" runat="server" CausesValidation="False" CommandName="Select" Text="Select"></asp:LinkButton> </ItemTemplate> </asp:TemplateField> <asp:BoundField DataField="CarNum" HeaderText="Car" ReadOnly="True" SortExpression="CarNum" /> <asp:BoundField DataField="CurrPassengers" HeaderText="Passengers" ReadOnly="True" SortExpression="CurrPassengers" /> <asp:BoundField DataField="MaxPassengers" HeaderText="Capacity" ReadOnly="True" SortExpression="MaxPassengers" /> <asp:BoundField DataField="Status" HeaderText="Status" ReadOnly="True" SortExpression="Status" /> <asp:BoundField DataField="StartAdd" HeaderText="Pick-Up Address" ReadOnly="True" SortExpression="StartAdd" /> <asp:BoundField DataField="EndAdd" HeaderText="Drop-Off Address" ReadOnly="True" SortExpression="EndAdd" /> <asp:BoundField DataField="AvgRideTime" HeaderText="Avg. Ride Time" ReadOnly="True" SortExpression="AvgRideTime" /> </Columns> <FooterStyle BackColor="#CCCCCC" ForeColor="Black" /> <HeaderStyle BackColor="#004812" Font-Bold="True" ForeColor="White" /> <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" /> <RowStyle BackColor="#EEEEEE" ForeColor="Black" /> <SelectedRowStyle BackColor="#C6940D" Font-Bold="True" ForeColor="White" /> <SortedAscendingCellStyle BackColor="#F1F1F1" /> <SortedAscendingHeaderStyle BackColor="#C6940D" /> <SortedDescendingCellStyle BackColor="#CAC9C9" /> <SortedDescendingHeaderStyle BackColor="#9F770B" /> </asp:GridView> </ContentTemplate> </asp:UpdatePanel>解决方案
Description
Assuming i understand your question.
You can use the ScriptManager to show a javascript alert message.
Sample protected void Page_Load(object sender, EventArgs e) { ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "err_msg", "alert('Dispatch assignment saved, but you forgot to click Confirm or Cancel!)');", true); }More Information
- MSDN - ClientScriptManager.RegisterStartupScript Method
更多推荐
ASP.NET:显示从C#code
发布评论