[已解决]在更新按钮上我想在javascript中显示消息以确认更新,我该怎么办? [英] [Solved] On update button I want Display message in javascript for confirmation to update, How can I do this?

查看:40
本文介绍了[已解决]在更新按钮上我想在javascript中显示消息以确认更新,我该怎么办?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我在Gridview的Update按钮上编写的代码。我想检查加权因子的总和,如果总数超过1,我想写javascript消息。我该怎么做。对vb代码中的Javascript嵌入不是很熟悉。



This is the code I have written on Update button of Gridview . I wanted to check total of weighting factor and I wanted to write the javascript message if total exceeds 1. How can I do this . Not very much familiar with Javascript Embeding in vb code .

Protected Sub UpdateFuncObjDetails(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs)
    lblwtFactTotalmsg.Visible = False
    Dim Conn As New SqlConnection(strConnString)
    Dim sum As Double = 0.0
    Dim str1 As String = String.Empty
    Dim Comm1 As New SqlCommand

    str1 = "select ISNULL(sum(MBO_Weighting_Factor),0) from tbl_MBO_Objective_Details where MBO_Req_Id is null and MBO_EMP_CODE='" & EMP_NO & "'"
    Comm1 = New SqlCommand(str1, Conn)
    Conn.Open()
    sum = Comm1.ExecuteScalar()
    Conn.Close()
' Here is code I want to check whether weighting factor exceeds 1 if it exceeds one 
' it should display message in javascript that 
' Your weghting factor total exceeds you can not 
'update the record

    Dim LblID As Integer = DirectCast(GridViewMBOFuncObjDetalis.Rows(e.RowIndex).FindControl("lblEditID"), Label).Text
    Dim txtfuncobj As String = DirectCast(GridViewMBOFuncObjDetalis.Rows(e.RowIndex).FindControl("txtfuncobj0"), TextBox).Text
    Dim txtmeasuredvar As String = DirectCast(GridViewMBOFuncObjDetalis.Rows(e.RowIndex).FindControl("txtmeasuredvar0"), TextBox).Text
    Dim txtdeadline As String = DirectCast(GridViewMBOFuncObjDetalis.Rows(e.RowIndex).FindControl("txtdeadline0"), TextBox).Text
    Dim txtweight_fact As String = DirectCast(GridViewMBOFuncObjDetalis.Rows(e.RowIndex).FindControl("txtweight_fact0"), TextBox).Text

    Dim con As New SqlConnection(strConnString)
    Dim cmd As New SqlCommand()
    cmd.CommandType = CommandType.Text
    cmd.CommandText = "update tbl_MBO_Objective_Details set MBO_Objective=@func_obj,MBO_Measured_Var=@mesrd_var,MBO_Target_Date=@tar_dt,MBO_Weighting_Factor=@wt_fact where id=@idnum;" & _
    " select id, MBO_Objective,MBO_Measured_Var,MBO_Target_Date,MBO_Weighting_Factor  from tbl_MBO_Objective_Details where MBO_Req_Id is null and MBO_Obj_Type_Id=1 and MBO_EMP_CODE='" & (EMP_NO) & "'"

    cmd.Parameters.Add("@idnum", SqlDbType.VarChar).Value = LblID
    cmd.Parameters.Add("@func_obj", SqlDbType.VarChar).Value = txtfuncobj
    cmd.Parameters.Add("@mesrd_var", SqlDbType.VarChar).Value = txtmeasuredvar
    cmd.Parameters.Add("@tar_dt", SqlDbType.VarChar).Value = txtdeadline
    cmd.Parameters.Add("@wt_fact", SqlDbType.VarChar).Value = txtweight_fact

    GridViewMBOFuncObjDetalis.EditIndex = -1
    GridViewMBOFuncObjDetalis.DataSource = GetDataMBOFuncObjDetails(cmd)
    GridViewMBOFuncObjDetalis.DataBind()
    BindDataMBOPerObjectives()

   End Sub

推荐答案

Hai



为什么你去寻找javascript?在你的检查地点(超过1或不)你使用条件和显示你的网络消息或继续你更新查询。像这样



Hai

why u go for javascript ? in ur check place (exceeds 1 or not) u use if condition and show ur web message or proceed ur update query.like this

    str1 = "select ISNULL(sum(MBO_Weighting_Factor),0) from tbl_MBO_Objective_Details where MBO_Req_Id is null and MBO_EMP_CODE='" & EMP_NO & "'"
    Comm1 = New SqlCommand(str1, Conn)
    Conn.Open()
    sum = Comm1.ExecuteScalar()
    Conn.Close()

If (sum > 1)Then
showmessage("Your weghting factor total exceeds you can not 
update the record")
Exit Sub 'This Exit Sub will exit the code execution,i mean here after code not execute it goes to end sub of the function

Else

   Dim LblID As Integer = DirectCast(GridViewMBOFuncObjDetalis.Rows(e.RowIndex).FindControl("lblEditID"), Label).Text
    Dim txtfuncobj As String = DirectCast(GridViewMBOFuncObjDetalis.Rows(e.RowIndex).FindControl("txtfuncobj0"), TextBox).Text
    Dim txtmeasuredvar As String = DirectCast(GridViewMBOFuncObjDetalis.Rows(e.RowIndex).FindControl("txtmeasuredvar0"), TextBox).Text
    Dim txtdeadline As String = DirectCast(GridViewMBOFuncObjDetalis.Rows(e.RowIndex).FindControl("txtdeadline0"), TextBox).Text
    Dim txtweight_fact As String = DirectCast(GridViewMBOFuncObjDetalis.Rows(e.RowIndex).FindControl("txtweight_fact0"), TextBox).Text
.................................
...........................
.....................

End If











如果你想要javascript msg提醒尝试这个,只需将这个javascript粘贴在脚本标签内的html页面中。我想总结你得到加权因子的总和,如果不是请尝试总计加权因子总和






if u want javascript msg alert try this ,just paste this javascript in html page inside Script tag.I think in sum u get total of weighting factor,if not pls try to get total of weighting factor in sum

function testmsg3(msg) {

 alert(msg);
           return false;

       }





及以下请查看检查地点(超过1或不超过1)







and in below pls see in checking place (exceeds 1 or not)


Protected Sub UpdateFuncObjDetails(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs)
    lblwtFactTotalmsg.Visible = False
    Dim Conn As New SqlConnection(strConnString)
    Dim sum As Double = 0.0
    Dim str1 As String = String.Empty
    Dim Comm1 As New SqlCommand
 
    str1 = "select ISNULL(sum(MBO_Weighting_Factor),0) from tbl_MBO_Objective_Details where MBO_Req_Id is null and MBO_EMP_CODE='" & EMP_NO & "'"
    Comm1 = New SqlCommand(str1, Conn)
    Conn.Open()
    sum = Comm1.ExecuteScalar()
    Conn.Close()
' Here is code I want to check whether weighting factor exceeds 1 if it exceeds one 
' it should display message in javascript that 
' Your weghting factor total exceeds you can not 
'update the record

if (sum >1) Then

 ScriptManager.RegisterStartupScript(Me.Page, Me.[GetType](), "Alert", "<script type='text/javascript'>testmsg3('Your weghting factor total exceeds you can not 
update the record !');</script>", False)

Else

    Dim LblID As Integer = DirectCast(GridViewMBOFuncObjDetalis.Rows(e.RowIndex).FindControl("lblEditID"), Label).Text
    Dim txtfuncobj As String = DirectCast(GridViewMBOFuncObjDetalis.Rows(e.RowIndex).FindControl("txtfuncobj0"), TextBox).Text
    Dim txtmeasuredvar As String = DirectCast(GridViewMBOFuncObjDetalis.Rows(e.RowIndex).FindControl("txtmeasuredvar0"), TextBox).Text
    Dim txtdeadline As String = DirectCast(GridViewMBOFuncObjDetalis.Rows(e.RowIndex).FindControl("txtdeadline0"), TextBox).Text
    Dim txtweight_fact As String = DirectCast(GridViewMBOFuncObjDetalis.Rows(e.RowIndex).FindControl("txtweight_fact0"), TextBox).Text
 
    Dim con As New SqlConnection(strConnString)
    Dim cmd As New SqlCommand()
    cmd.CommandType = CommandType.Text
    cmd.CommandText = "update tbl_MBO_Objective_Details set MBO_Objective=@func_obj,MBO_Measured_Var=@mesrd_var,MBO_Target_Date=@tar_dt,MBO_Weighting_Factor=@wt_fact where id=@idnum;" & _
    " select id, MBO_Objective,MBO_Measured_Var,MBO_Target_Date,MBO_Weighting_Factor  from tbl_MBO_Objective_Details where MBO_Req_Id is null and MBO_Obj_Type_Id=1 and MBO_EMP_CODE='" & (EMP_NO) & "'"
 
    cmd.Parameters.Add("@idnum", SqlDbType.VarChar).Value = LblID
    cmd.Parameters.Add("@func_obj", SqlDbType.VarChar).Value = txtfuncobj
    cmd.Parameters.Add("@mesrd_var", SqlDbType.VarChar).Value = txtmeasuredvar
    cmd.Parameters.Add("@tar_dt", SqlDbType.VarChar).Value = txtdeadline
    cmd.Parameters.Add("@wt_fact", SqlDbType.VarChar).Value = txtweight_fact
 
    GridViewMBOFuncObjDetalis.EditIndex = -1
    GridViewMBOFuncObjDetalis.DataSource = GetDataMBOFuncObjDetails(cmd)
    GridViewMBOFuncObjDetalis.DataBind()
    BindDataMBOPerObjectives()
  End If
   End Sub


这篇关于[已解决]在更新按钮上我想在javascript中显示消息以确认更新,我该怎么办?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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