วันอาทิตย์ที่ 8 กุมภาพันธ์ พ.ศ. 2558

javascript: How to upload a file on the click of a button.

<script type="text/javascript">
function loadCommand(btn) {
document.getElementById("fiUpload").click();
}
function AlertFilesize(ClientID) {
if (window.ActiveXObject) {
var fso = new ActiveXObject("Scripting.FileSystemObject");
var filepath = ClientID.value;
var thefile = fso.getFile(filepath);
var sizeinbytes = thefile.size;

} else {

var sizeinbytes = ClientID.files[0].size;
}

var fSExt = new Array('Bytes', 'KB', 'MB', 'GB');
fSize = sizeinbytes / 1024; i = 0;

if (Math.round(fSize * 100) / 100 >= 7168) {
ClientID.value = null;
alert("ขนาดเกิน:" + fSize);
}

document.getElementById("btnLoad").innerHTML = '<i class="fa fa-spinner fa-spin fa-lg"></i> Please Wait';
document.getElementById("btnUpload").click();
}
</script>

<asp:FileUpload ID="fiUpload" runat="server" Width="455px"   style ="display:none" onchange="AlertFilesize(this);" />
<asp:LinkButton ID="btnUpload" runat="server"  style ="display:none"   ></asp:LinkButton>                                      
<input id ="btnLoad" type ="button" onclick="loadCommand(this); return;" value ="Upload File" />

************** VB.net ****************
    Protected Sub btnUpload_Click(sender As Object, e As EventArgs) Handles btnUpload.Click
        fiUpload.SaveAs(Server.MapPath(fiUpload.FileName))
    End Sub

wait for button click javascript







<script type="text/javascript">

     function loadCommand(btn) {
         /*document.getElementById("btnUpload").innerHTML = '<i class="fa fa-spinner fa-spin fa-lg"></i> Please Wait';*/
         btn.innerHTML = '<i class="fa fa-spinner fa-spin fa-lg"></i> Please Wait';
     }
</script>

***********************
<asp:LinkButton ID="btnUpload" runat="server" CssClass="btn-u btn-u-orange btn-u-lg" OnClientClick ="loadCommand(this);" > upload file</asp:LinkButton>
***********************


วันเสาร์ที่ 7 กุมภาพันธ์ พ.ศ. 2558

GridView1_RowCommand

    Private Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand

        Select Case e.CommandName
            Case "btnOk"
                Dim row As GridViewRow = DirectCast(DirectCast(e.CommandSource, Control).NamingContainer, GridViewRow)
                Dim projectID As HiddenField = DirectCast(row.FindControl("projectID"), HiddenField)
                Dim txtNote As TextBox = DirectCast(row.FindControl("txtNote"), TextBox)

                Dim obj As New DataClassesProjectViewDataContext
                obj.ProjectCancelUpdateComment(projectID.Value, txtNote.Text)
        End Select

    End Sub

การใช้ WebClient สำหรับเรียก URL

Dim _url As String = " https :// www . MyDomain . com /?q=ทดสอบ " Dim wc As New System . Net . WebClient () wc . Encodin...