javascript函数在asp.net中不起作用 [英] javascript function is not working in asp.net
问题描述
javascript功能不起作用。如何解决这个问题:
aspx页面:
< pre lang =Javascript>< div>
< style type = text / css>
.black_overlay {
display:none;
仓位:绝对;
top:0%;剩余
:0%;
宽度:100%;
身高:100%;
background-color:black;
z-index: 1001 ;
-moz-opacity: 0 。 8 ;
opacity:。 80 ;
filter:alpha(opacity = 80 );
}
.popup {
宽度:439px;
身高:365px;
头寸:固定;
top:50%;剩余
:36%;
右:10%;
底部:50%;
保证金:-50px 0 0 -100px; / * [ - (height / 2)px 0 0 - (width / 2)px] * /
z-index: 2222 ;
background-color:#FFFFFF;
颜色:白色;
可见性:隐藏;
}
.style1
{
身高:15px;
}
.style2
{
宽度:40%;
身高:97px;
}
.style3
{
身高:97px;
}
< / style >
< script type = text / javascript< /跨度>>
function show_popup(pric){
// 从代码后面调用...
var popup = document .getElementById(' <%= popup.ClientID%>'跨度>);
popup.style.visibility = ' visible';
document .getElementById(' Div1').style.display = ' block';
document .getElementById(' <% = lblnotice.ClientID%>')。innerHTML = pric;
return false ;
}
function hidePopup(){
var popup = < span class =code-sdkkeyword> document .getElementById(' <%= popup.ClientID% >'跨度>);
popup.style.visibility = ' hidden';
document .getElementById(' Div1').style.display = ' none';
return false ;
}
< / script>
< asp:DataList ID = dl runat = server OnItemDataBound = item_bound跨度>>
< itemtemplate>
< asp:Label ID = ru Text = ' <%#DataBinder.Eval(Container.DataItem,name)%>' runat = server>
< asp:LinkButton ID = lnkviewcart CausesValidation = true已启用= true CommandName = imgclicked Visible = false runat = server Text = 参见购物车中的价格>
< / itemtemplate >
< div id = Div1 class = black_overlay>
< / div >
< div id = popup align = center class = popup runat = server 跨度>>
< table width = 100% style = removed50%;>
< tr>< td>< hr style = height:10px; background-color: #ff0000; /> < / td > < / tr >
< tr align = center style = < span class =code-string> width:90%;>< td align = left style = color :#565454;>< table width = 100%> < tr>< td style = font-family:Verdana; font-size:16px; color:#565454 ;>你的Price @ Lee ' s Tools< / td>
< td>< asp:Label ID =lblnoticerunat =serverForeColor =#ff0000Font-Names =VerdanaFont-Size =15pxFont-Bold =true >< / TD>< / TR>< /表>< / TD>< / TR>
< tr>< td>< hr style =height:4px; background-color:#ff0000; />< / TD>< / TR>
< tr>< td>< / td>< / tr>
< tr>
< td align =right>
< table width =100%>
< tr>< td align =left>< asp:ImageButton ID =imgcloserunat =serverImageUrl =../ Image / closebut.pngOnClientClick =return hidePopup (); /> < / TD>
< td align =right>< asp:ImageButton ID =imgpopaddrunat =serverImageUrl =../ Image / Addtocart / cart_button.pngOnClick =addtocart_clicked_popup/> ; < / TD>
< / tr>
< / table>
< / td>< / tr>
< tr>< td>< / td>< / tr>
< / table>
< / div>
aspx。 cs:
使用系统;
);
使用 System.Collections.Generic;
使用 System.Linq;
使用 System.Web;
使用 System.Web.UI;
使用 System.Web.UI.WebControls;
使用 System.Data;
使用 System.Data.SqlClient;
命名空间 popjavascript
{
public partial class WebForm1:System.Web.UI.Page
{
protected void Page_Load( object sender,EventArgs e)
{
if (!Page.IsPostBack)
{
Bind();
}
}
public void Bind()
{
DataTable dt = new DataTable( < span class =code-string> new
dt.Columns.Add( name);
dt.Columns.Add( price);
dt.Rows.Add( christh, 100.00);
// dt.Rows.Add(100.00,price );
dl.DataSource = dt;
dl.DataBind();
}
受保护 void addtocart_clicked_popup( object sender,ImageClickEventArgs e)
{
Response.Write( 你好跨度>);
}
受保护 void item_bound( object sender,DataListItemEventArgs e)
{
LinkButton linkmp =(LinkButton)e.Item.FindControl( lnkviewcart);
Label lblprice =(Label)e.Item.FindControl( ru);
linkmp.Visible = true ;
linkmp.OnClientClick = retun show_popup(' + lblprice.ToString()。Trim ()+ '); retun false;;
}
}
}
需要帮助。
christhuxavier写道:我很抱歉不清楚。 ..我的意思是当我点击点击按钮查看购物车中的价格时,我的Javascript功能没有被调用。
[文本被修改以修复一些错误 - SA]
它没有工作只是因为你没有写一个代码来调用它。
其中一个方法就是这个(在jQuery库的帮助下) :
( document )。ready( function (){
( #lnkviewcart)。click( function (){ // 其中id =lnkvi ewcartfor
// 点击一下,可以使用
javascript function is not working. how to solve this problem:
aspx Page:
<div>
<style type="text/css">
.black_overlay{
display:none;
position: absolute;
top: 0%;
left: 0%;
width: 100%;
height: 100%;
background-color:black;
z-index:1001;
-moz-opacity: 0.8;
opacity:.80;
filter: alpha(opacity=80);
}
.popup {
width:439px;
height:365px;
position:fixed;
top:50%;
left:36%;
right:10%;
bottom:50%;
margin:-50px 0 0 -100px; /* [-(height/2)px 0 0 -(width/2)px] */
z-index:2222;
background-color:#FFFFFF;
color:White;
visibility:hidden;
}
.style1
{
height: 15px;
}
.style2
{
width: 40%;
height: 97px;
}
.style3
{
height: 97px;
}
</style>
<script type="text/javascript">
function show_popup(pric) {
//calling from code behind...
var popup = document.getElementById('<%=popup.ClientID %>');
popup.style.visibility = 'visible';
document.getElementById('Div1').style.display = 'block';
document.getElementById('<%=lblnotice.ClientID %>').innerHTML = pric;
return false;
}
function hidePopup() {
var popup = document.getElementById('<%=popup.ClientID %>');
popup.style.visibility = 'hidden';
document.getElementById('Div1').style.display = 'none';
return false;
}
</script>
<asp:DataList ID="dl" runat="server" OnItemDataBound="item_bound">
<itemtemplate>
<asp:Label ID="ru" Text='<%# DataBinder.Eval(Container.DataItem,"name")%>' runat="server">
<asp:LinkButton ID="lnkviewcart" CausesValidation="true" Enabled="true" CommandName="imgclicked" Visible="false" runat="server" Text="See Price in Cart" >
</itemtemplate>
<div id="Div1" class="black_overlay">
</div>
<div id="popup" align="center" class="popup" runat="server">
<table width="100%" style="removed50%;">
<tr><td><hr style=" height:10px; background-color:#ff0000;" /></td></tr>
<tr align="center" style=" width:90%;"><td align="left" style=" color:#565454;"><table width="100%"><tr><td style="font-family:Verdana; font-size:16px; color:#565454; ">Your Price @ Lee's Tools</td>
<td><asp:Label ID="lblnotice" runat="server" ForeColor="#ff0000" Font-Names="Verdana" Font-Size="15px" Font-Bold="true"></td></tr></table></td></tr>
<tr><td><hr style=" height:4px; background-color:#ff0000;" /></td></tr>
<tr><td></td></tr>
<tr>
<td align="right">
<table width="100%">
<tr><td align="left"><asp:ImageButton ID="imgclose" runat="server" ImageUrl="../Image/closebut.png" OnClientClick="return hidePopup();" /> </td>
<td align="right"><asp:ImageButton ID="imgpopadd" runat="server" ImageUrl="../Image/Addtocart/cart_button.png" OnClick="addtocart_clicked_popup" /> </td>
</tr>
</table>
</td></tr>
<tr><td></td></tr>
</table>
</div>
aspx.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
namespace popjavascript
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
Bind();
}
}
public void Bind()
{
DataTable dt = new DataTable("new");
dt.Columns.Add("name");
dt.Columns.Add("price");
dt.Rows.Add("christh", "100.00");
// dt.Rows.Add("100.00","price");
dl.DataSource = dt;
dl.DataBind();
}
protected void addtocart_clicked_popup(object sender, ImageClickEventArgs e)
{
Response.Write("hello");
}
protected void item_bound(object sender, DataListItemEventArgs e)
{
LinkButton linkmp = (LinkButton)e.Item.FindControl("lnkviewcart");
Label lblprice = (Label)e.Item.FindControl("ru");
linkmp.Visible = true;
linkmp.OnClientClick = "retun show_popup(' " + lblprice.ToString().Trim() + "'); retun false;";
}
}
}
help needed.
解决方案 christhuxavier wrote:I am sorry for not clear... I mean my Javascript function is not invoked when I click on click button "See Price in Cart".
[text modified to fix a number of mistakes — SA]
It does not work just because you did not write a single word of code to invoke it.
One of the many ways to do that is this (with the help of jQuery library):
(document).ready(function() {
("#lnkviewcart").click(function() { // where id="lnkviewcart" for
// do something on click, can use
这篇关于javascript函数在asp.net中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!