.CS
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
btSubmit.Attributes.Add("onClick", "return Submit();");
}
} //点击按钮时
protected void btSubmit_Click(object sender, EventArgs e)
{
hfCount.Value = Convert.ToString(m - n); //m,n为两个变量
string strUrl = string.Empty;
string strTypeID = Request.QueryString["TestFeelID"].ToString();
strUrl = "TestEnd.aspx?TypeID=" + strTypeID + "";
Response.Redirect(strUrl);
}.aspx中:
<script language="javascript" type="text/javascript">
var mCount;
var strTemp;
function Submit()
{
mCount = document.all('hfCount').value;
if ( mCount == "0" )
{
return confirm('确定要提交吗?');
}
else
{
strTemp = "您还有未完成,确定要提交吗?";
return confirm(strTemp);
}
}
</script>现在在的困惑是:JavaScript中的document.all('hfCount').value一直为空!
望各位高手不吝赐教~
谢谢~~~
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
btSubmit.Attributes.Add("onClick", "return Submit();");
}
} //点击按钮时
protected void btSubmit_Click(object sender, EventArgs e)
{
hfCount.Value = Convert.ToString(m - n); //m,n为两个变量
string strUrl = string.Empty;
string strTypeID = Request.QueryString["TestFeelID"].ToString();
strUrl = "TestEnd.aspx?TypeID=" + strTypeID + "";
Response.Redirect(strUrl);
}.aspx中:
<script language="javascript" type="text/javascript">
var mCount;
var strTemp;
function Submit()
{
mCount = document.all('hfCount').value;
if ( mCount == "0" )
{
return confirm('确定要提交吗?');
}
else
{
strTemp = "您还有未完成,确定要提交吗?";
return confirm(strTemp);
}
}
</script>现在在的困惑是:JavaScript中的document.all('hfCount').value一直为空!
望各位高手不吝赐教~
谢谢~~~
解决方案 »
- 怎么在每天的固定时间执行一段代码呢
- 某按钮,按了后就能把设定好的邮件内容发给这人,还有其他人的类似按钮,这功能怎么做
- 生成的隨機數為什么一樣,怎樣才能不一樣
- 分享一个我的分页代码
- 开发网站和开发局域网项目路径的问题.
- 请问我装完VS。NET2003后发现IE浏览到宋体字体的时候出现了毛病
- 简单问题??????
- ASP.NET里用什么做增加、删除、修改?用什么做报表打印?
- 如何将这段字符串连接起来
- 如何按当天日期读取某个文件夹下面的当天的txt文件,
- 网上视频点播,统计流量
- CSS问题:我用div+css构造了一个表的样式,其中的div代码比较多,表的样式用得也多,能不能能这些div代码也嵌入CSS,调用时只用少量代码?
是个什么控件,值是哪儿来的?
它的值是在Click事件的时候给的~
mCount = document.getElementById( 'hfCount ').value;
改为这个试一下。
mCount = document.getElementById( 'hfCount ').value;
==================================================================================
谢谢~~~
试过,也不行~
document.getElementById(<%= "'"+ this.hfCount.ClientID + "'"%>)试试
hfCount.Value = Convert.ToString(m - n); 这句执行通过了吗?
document.getElementById( <%= " '"+ this.hfCount.ClientID + " '"% >)试试
===========================================================================================
还没有运行就报错~============================================================================================
蓝色妖姬mCount = document.getElementById( 'hfCount ').value; 这个不会有问题吧,以前都是这样用的,没有问题啊,看看你控件的名字是不是写错了?
===============================================================================================
没有写错~
<asp:HiddenField ID="hfCount" runat="server" / >谢谢~~~
发表于:2007-10-22 18:28:1310楼 得分:0
还有就是看看你的hfCount控件是不是真的被赋值了
hfCount.Value = Convert.ToString(m - n); 这句执行通过了吗?
================================================
这一句在弹出确认框后才被执行,我想应该是程序执行顺序的问题!
但不知道怎么解决~
发表于:2007-10-22 18:29:5311楼 得分:0
document.getElementById( ' <%= hfCount.ClientID% > ')
===============================================
还没有运行就报错~
???
不可能吧,把多余的空格删掉
要不你把你的画面得到的HTML程序贴出来吧
.aspx
<body>
<script type="text/javascript">
<!--
var mCount;
function test()
{
mCount = document.getElementById(<%= "'"+ this.hfCount.ClientID + "'"%>).value;
alert(mCount);
}
// -->
</script>
<form id="form1" runat="server">
<div>
<input id="Button1" type="button" value="button" onclick="return test();"/>
<asp:HiddenField ID="hfCount" runat="server" />
</div>
</form>
</body>
.cs
protected void Page_Load(object sender, EventArgs e)
{
this.hfCount.Value = "20";
}
发表于:2007-10-22 19:19:3217楼 得分:0
以下是我的例子,没问题啊
.aspx
<body >
<script type="text/javascript" >
<!--
var mCount;
function test()
{
mCount = document.getElementById( <%= " '"+ this.hfCount.ClientID + " '"% >).value;
alert(mCount);
}
// -- >
</script >
<form id="form1" runat="server" >
<div >
<input id="Button1" type="button" value="button" onclick="return test();"/ >
<asp:HiddenField ID="hfCount" runat="server" / >
</div >
</form >
</body >
.cs
protected void Page_Load(object sender, EventArgs e)
{
this.hfCount.Value = "20";
} ======================================================
谢谢,我的Button是服务器端Button!点击后往数据库插入记录~~~
这一句在弹出确认框后才被执行,我想应该是程序执行顺序的问题!
但不知道怎么解决~
function test()
{
mCount = document.getElementById( <%= " '"+ this.hfCount.ClientID + " '"% >).value;
alert(mCount);
} CS:
page_load事件中
btSubmit.Attributes.Add("onclick", "test()");
LZ个人问题-----
function test()
{
mCount = document.getElementById( <%= " '"+ this.hfCount.ClientID + " '"% >).value;
alert(mCount);
} CS:
page_load事件中
btSubmit.Attributes.Add("onclick", "test()");
=============================================================================================
不太明白?
client 端的代码是先于服务器端事件执行的。这是机制问题。估计改是改不了的。 你可以定义公共变量,然后试着在客户端用 <%=你的变量% >来取得
==============================================================================
这个机制问题还没有其他的解决办法,怎样解决,望各位高手不吝赐教!
{
hfCount.Value = Convert.ToString(m - n); //m,n为两个变量
string strUrl = string.Empty;
string strTypeID = Request.QueryString["TestFeelID"].ToString();
if(hfCount.Value=="0")
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "go", "<script language='javascript'>if(confirm('确定要提交吗?')){window.location.href='TestEnd.aspx?TypeID=" + strTypeID + "';}</script>"); }
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "go", "<script language='javascript'>if(confirm('您还有未完成,确定要提交吗?')){window.location.href='TestEnd.aspx?TypeID=" + strTypeID + "';}</script>");
}
}
mCount = document.getElementById( 'hfCount ').value; 肯定行!
==========================================================================================
hfCount.Value如果是一个固定的值话,是没有问题,但现在的问题是我是在
protected void btSubmit_Click(object sender, EventArgs e)事件中给hfCount赋值,赋值语句为:
hfCount.Value = Convert.ToString(m - n);
该语句是在在弹出确认框后才被执行,而hfCount.Value应该在弹出对话框前就得有值~
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>無題のページ</title>
<script type="text/javascript">
function test()
{
alert(<%=value1%>-<%=value2%>);
}
</script>
</head><body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" OnClientClick="test()" OnClick="Button1_Click" Text="Button" /></div>
</form>
</body>
</html>
public partial class passvalue : System.Web.UI.Page
{
public int value1 = 3;
public int value2= 23; protected void Page_Load(object sender, EventArgs e)
{ }
protected void Button1_Click(object sender, EventArgs e)
{ }
}
honey52570说的没错,是机制问题,建议你有时间学习一下ASP.NET的机理
如果你的BUTTON点击引起的POST过程里m和n没有变化,可以直接
if ( <%= m-n %> == "0" )
根本不用什么控件
如果点击事件里会引起m或n的变化,只好用RegisterStartupScript再引发一次POST
2.
function test()
{
mCount = document.getElementById( <%= " '"+ this.hfCount.ClientID + " '"% >).value;
alert(mCount);
} CS:
page_load事件中
btSubmit.Attributes.Add("onclick", "test()");
=============================================================================================
>>不太明白?哪里不明白
3.
>>谢谢,我的Button是服务器端Button!点击后往数据库插入记录~~~ Server端BUTTON在HTML里一定也是HTML BUTTON
如果你只是测试Javascript,用HTML BUTTON更直接
只要你的m,n再先于buttonclick之前能赋上值,那么就可以取得
================================================================
m,n是在buttonclick之后得到的
Server端BUTTON在HTML里一定也是HTML BUTTON
如果你只是测试Javascript,用HTML BUTTON更直接
====================================================================
不是测试JavaScript
之后得到的就用ClientScript.RegisterStartupScript
==========================================================
谢谢,ClientScript.RegisterStartupScript 怎么用?
protected void btSubmit_Click(object sender, EventArgs e)
{
hfCount.Value = Convert.ToString(m - n); //m,n为两个变量
string strUrl = string.Empty;
string strTypeID = Request.QueryString["TestFeelID"].ToString();
if(hfCount.Value=="0")
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "go", " <script language= 'javascript ' >if(confirm( '确定要提交吗? ')){window.location.href= 'TestEnd.aspx?TypeID=" + strTypeID + " ';} </script >"); }
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "go", " <script language= 'javascript ' >if(confirm( '您还有未完成,确定要提交吗? ')){window.location.href= 'TestEnd.aspx?TypeID=" + strTypeID + " ';} </script >");
}
}