以下是点击确定按钮之后,分别热行的aspx页面里面的javascript函数,和相应的cs页面的函数.
aspx页面.
function confirm()
{
var flag = true;
var flagtime = true;
if("" == document.all.item("txtTitle").value || "<>" == document.all.item("txtTitle").value) 
{
alert("标题不能为空!");
document.all.item('divID1').style.display = "block";
document.all.item('divID2').style.display = "none";
document.all.item('divID3').style.display = "none";
document.all.item('txt').value = "1";
document.all.txtTitle.focus();
flag = false;
document.all.item("txtTitle").value = "";
}
//若标题没有填,则不进行是否选择了人员的测试
if(true == flag)
{
if(document.all.uctrlResive_LisBoxSendTo.length == 0 
&& document.all.uctrlResive_LisBoxSecretTo.length == 0) 
{
alert("你必须至少选择一个收件人或密送人!");
document.all.item('divID2').style.display = "block";
document.all.item('divID1').style.display = "none";
document.all.item('divID3').style.display = "none";
document.all.item('txt').value = "2";
flagtime = false
}
} document.all.item("uctrlResive_txtbox").value = "3"; 
<TD><BUTTON class="mybutton1" id="btnOK" onmouseover="this.className='mybutton2'" onclick="javascript:void(0);confirm();"
onmouseout="this.className='mybutton1'" type="button" runat="server">确定</BUTTON>&nbsp;&nbsp;以下CS页面确定按钮对应该的函数.
private void btnOK_ServerClick(object sender, System.EventArgs e)
{
MsgCont msgobj = GetMsgObj();
if(msgobj.SendToID != null || msgobj.SecretTo != null)
{
if("2" == flag)
{
//调用数据访问层,再次发送信息
(new MsgObj()).InsertAgain(Request.Params["MessageID"].ToString(),msgobj,0);
}
//如果是发送新信息
else
{
(new MsgObj()).InsertMessage(msgobj,"发送",Convert.ToInt16(this.Empid));
}
Response.Redirect("MessageDo.aspx?flag=1");
}
}现在我遇到的问题是:在if(true=flag)和if(document.all.uctrlResive_LisBoxSendTo.length == 0 
&& document.all.uctrlResive_LisBoxSecretTo.length == 0) 都成立的情况下.点击确定按钮仍然会执行
Response.Redirect("MessageDo.aspx?flag=1");而且alert("你必须至少选择一个收件人或密送人!");这句话也会执行,但是最后还是会执行Response.Redirect("MessageDo.aspx?flag=1");这个问题该怎么解决呢.请高手指点!拜谢!拜谢!

解决方案 »

  1.   

    在cs 里写  btnOK.Attriblue.Add("onclick","javascript:return 函数名") 
      Attriblue 可能写错了 你自己对着看看吧
      

  2.   

    在Page_load里加
    btnOK.Attribute.Add("onclick","javascript:return 函数名");在btnOK_ServerClick方法里的Flag参数你是如何获取的?
      

  3.   

    <BUTTON class="mybutton1" id="btnOK" onmouseover="this.className='mybutton2'" onclick="javascript:void(0);confirm();"
    onmouseout="this.className='mybutton1'" type="button" runat="server">确定</BUTTON>这是什么东西 JS 要有返回值  老大
      

  4.   

    回:zhf777(八步)
    flag参数是在page_Load里面有这一句话!
    if(Request.Params["flag"]!= null)
    {
    flag = Request.Params["flag"].ToString();
    }
      

  5.   

    <BUTTON class="mybutton1" id="btnOK" onmouseover="this.className='mybutton2'" onclick="javascript:void(0);confirm();"
    onmouseout="this.className='mybutton1'" type="button" runat="server">确定</BUTTON>这一句不是Js里面的.是html里面的.是系统自动生成的.我是让大家看的清楚,才贴上去的.不好意思!
      

  6.   

    function confirm()
    {
    var flag = true;
    var flagtime = true;
    if("" == document.all.item("txtTitle").value || "<>" == document.all.item("txtTitle").value) 
    {
    alert("标题不能为空!");
    document.all.item('divID1').style.display = "block";
    document.all.item('divID2').style.display = "none";
    document.all.item('divID3').style.display = "none";
    document.all.item('txt').value = "1";
    document.all.txtTitle.focus();
    flag = false;
    document.all.item("txtTitle").value = "";
    }
    //若标题没有填,则不进行是否选择了人员的测试
    if(true == flag)
    {
    if(document.all.uctrlResive_LisBoxSendTo.length == 0 
    && document.all.uctrlResive_LisBoxSecretTo.length == 0) 
    {
    alert("你必须至少选择一个收件人或密送人!");
    return false;//////////////////////////
    document.all.item('divID2').style.display = "block";
    document.all.item('divID1').style.display = "none";
    document.all.item('divID3').style.display = "none";
    document.all.item('txt').value = "2";
    flagtime = false
    }
    }
      

  7.   

    btnOK.Attribute.Add("onclick","javascript:return confirm()");这样再OK了吧
      

  8.   

    回:wuxing2006
    这样做也不行的.还是会执行Response.Redirect("MessageDo.aspx?flag=1");
    不过谢谢了!