在C#中完成代码之前提交java脚本函数 [英] Submit java script function before code behind complete in C#

查看:78
本文介绍了在C#中完成代码之前提交java脚本函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个功能显示弹出消息为对话框,当用户点击确定时,它会更新其他显示另一条消息,问题是该功能在我点击确定或取消之前给我没有更新,我怎么能解决这个问题问题?



我尝试了什么:



I have this function to show pop up message as dialog box , when user click ok , it will update else show another message , the problem is the function give me not updated before I click ok or cancel , how I can Solve this Problem?

What I have tried:

public void save_date(string Name, string Date,System.Web.UI.WebControls.Label lableMessage)
   {
           connection.Open();
           SqlCommand cmdselect = new SqlCommand("SELECT COUNT(*) FROM Exam WHERE ExamName='"+Name+"' and CourseNum='" + course_number + "'and Semster='"+semester+"'", connection);
           int num = (int)cmdselect.ExecuteScalar();
           if (num > 0 )
           {
               ScriptManager.RegisterStartupScript(this, typeof(string), "Submit", "funCheck('The Date is Already exist .Do You want to update it?');", true);
               //DialogResult Dialog = MessageBox.Show(" The Date is Already exist .Do You want to update it?", Name, MessageBoxButtons.YesNo);
               //if (Dialog == DialogResult.Yes)
               if (HiddenField1.Value == "1")
               {
                   SqlCommand cmdUpdate = new SqlCommand("UPDATE Exam SET Date='" + Date + "',Semster='"+semester+"'WHERE ExamName='"+Name+"'and CourseNum='" + course_number + "'", connection);
                   cmdUpdate.ExecuteNonQuery();
                   lableMessage.Text="Date Updated Successfully";
               }//end if
               else
               {
                   lableMessage.Text="Not Updated";
                   connection.Close();
                   Load_Items();
               }//end else


           }
           else
           {
               SqlCommand cmd = new SqlCommand("INSERT INTO Exam(CourseNum,Semster,ExamName,Date) VALUES ('" + course_number + "','"+semester+"','"+Name+"' ,'"+Date + "')", connection);
               cmd.ExecuteNonQuery();
               lableMessage.Text="Date Saved Successfully";
           }
           connection.Close();


   }//save date





这就是Java脚本代码:









and that's the Java script code :



script  type="text/javascript" >
        function funCheck(msg) {
            var flag = confirm(msg);
            var hdnfld = document.getElementById('<%= HiddenField1.ClientID %>');
            hdnfld.value = flag ? '1' : '0';
            
        }

推荐答案

解决此问题的几种方法详见这里。您可能不得不将代码流分为两个阶段,但这不是一个小问题。
A few ways of tackling this are detailed here. You're probably going to have to split your code flow into a two-stage process though so it's not a trivial issue.


这篇关于在C#中完成代码之前提交java脚本函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆