2012年8月8日 星期三

HTML 使用 Javascript 執行 PostBack 並傳遞參數回 Server 的做法


<!-- Client -->
    <div>
        <ul>
            <li style="cursor:pointer" onclick="javascript: __doPostBack('','SortSNDesc');" >User SN Desc</li>
            <li style="cursor:pointer" onclick="javascript: __doPostBack('','SortName');">User Name</li>
        </ul>
    </div>


' Server Code Behind
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If IsPostBack Then
            Select Case Request("__EVENTARGUMENT")
                Case "SortSNDesc"
                    ListView1.Sort("UserSN", SortDirection.Descending)
                Case "SortName"
                    ListView1.Sort("FullName", SortDirection.Ascending)
            End Select
        End If
    End Sub