2017年10月20日 星期五

[ASP.NET] vb.net call javascript function

vb.net call javascript function

一、
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="javascript:openUserAppSetting();return false;" />

二、
<asp:Button ID="but_save" runat="server" Text="提交變更" class="btn btn-primary"  OnClientClick="return openUserAppSetting();"/>

<asp:Button id="Button2" runat="server" Text="XD" OnClientClick="closeUserAppSetting();" OnClick="Button2_Click"  UseSubmitBehavior="false" />
OnClientClick會在onclick之前執行

三、
ScriptManager.RegisterClientScriptBlock(Me, Me.GetType(), "", "showDisplay()", True)
ScriptManager.RegisterStartupScript(Me, Page.GetType, "Script", "showDisplay();", True)

<script type="text/javascript">
        function openUserAppSetting() {
            $('#userAppSetting').skygqbox();
        }

        function closeUserAppSetting() {
            $('#userAppSetting').hide();
        }
</script>



HTML/javascript call vb function

[ HTML ]
<td onclick="callServersideFunction()">日期</td>

[ javascript ]
//call vb function
 function callServersideFunction() {
         var someValueToPass = name;
          __doPostBack('CustomPostBack', someValueToPass);

}

[ vb ]
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    ' Insure that the __doPostBack() JavaScript method is created...
    Me.ClientScript.GetPostBackEventReference(Me, String.Empty)

    'If IsPostBack = False Then
    Dim eventTarget As String = ""
    Dim eventArgument As String = ""

    If Request("__EVENTTARGET") Is Nothing Then
        eventTarget = String.Empty
    Else
        eventTarget = Request("__EVENTTARGET")
    End If

    If Request("__EVENTARGUMENT") Is Nothing Then
        eventArgument = String.Empty
    Else
        eventArgument = Request("__EVENTARGUMENT")
    End If

    If eventTarget = "CustomPostBack" Then
        Dim valuePassed As String = eventArgument
        ' there call function....
    End If
    ' End If

End Sub







[ASP.NET]判斷要寫入的資料是否與資料表相同,若不相同才進行更新

Function IsRowModified_u(ByVal r As GridViewRow) As Boolean
        Dim Curr_OrgID As String
        Dim Curr_HomoID As String
        Dim Curr_LineNum As String
        Dim lv_RadioButtonList As String
        Dim lv_HAZARDOUS_VALUE As String
        Dim lv_REASON As String

        Curr_OrgID = CType(r.FindControl("lb_org_id"), Label).Text 'Convert.ToInt32(GridView1.DataKeys(0).Value)
        Curr_HomoID = CType(r.FindControl("lb_HOMOGENOUS_MAT_ID"), Label).Text
        Curr_LineNum = CType(r.FindControl("lb_LINE_NUM"), Label).Text

        lv_RadioButtonList = CType(r.FindControl("RadioButtonList1"), RadioButtonList).Text
        lv_HAZARDOUS_VALUE = CType(r.FindControl("tb_HAZARDOUS_VALUE"), TextBox).Text
        lv_REASON = CType(r.FindControl("tb_REASON"), TextBox).Text

        Dim row As DataRow = originalDataTable_u.[Select]([String].Format("org_id = {0} and HOMOGENOUS_MAT_ID={1} and line_num={2}", Curr_OrgID, Curr_HomoID, Curr_LineNum))(0)

        If lv_RadioButtonList.Equals(row("INCLUDE_YN").ToString()) = True And _
            lv_HAZARDOUS_VALUE.Equals(row("HAZARDOUS_VALUE").ToString()) = True And _
            lv_REASON.Equals(row("REASON").ToString()) = True Then
            Return True
        Else
            Return False
        End If

        'Return False
    End Function