2013 m. rugsėjo 17 d., antradienis

decimal(4,1) vs. decimal(4,2)

(4,1): 4 - kiek pozicijų iš viso, 1- kiek pozicijų iš jų skirta po kablelio. t.y. max skaičius 999,9.  (4,2): max skaičius 99,99

Disable Browser Back Button Using JavaScript ASP.NET

Sprendimas:

JavaScript:

function disableBackButton()
{
window.history.forward();
}
setTimeout("disableBackButton()", 0);
< body   onunload=" disableBackButton() " >

http://www.codeproject.com/Questions/89384/Disable-Browser-Back-Button-Using-Javascript-ASP-N.aspx

2013 m. rugsėjo 12 d., ketvirtadienis

Datos formatas pagal lokalią kalbą JavaScript ir ASP.NET

Problema: atnaujinant duomenis su JavaScript, dažnai reikia išlaikyti datos formatą pagal lokalią kalbą.

Sprendimas:

var d = new Date(MeetDate).localeFormat("d"); - JavaScript

< % #  Eval("MeetDate", " { 0 : d } ") % > - ASP.NET

Daugiau: http://www.asp.net/AJAX/Documentation/Live/ClientReference/Global/JavascriptTypeExtensions/DateTypeExt/default.aspx

In Chapter 6: ASP.NET AJAX Localization, on page 289, we have a tip on Data Format Strings. It states that “the data format strings available for the Date and Number types in JavaScript are the same as those that are available in .NET for the DateTime and Double types.” This is incorrect.
The format strings that are allowed for Number types are the following:
  • c or C: Currency
  • p or P: Percentage
  • d or D“: Decimal (# number of digits)
  • n or N“: Numeric (# number of digits after decimal)
- e, f, g, r, x, and custom format strings are not supported
The standard format strings that are allowed for the Date type are the following:
  • d: Short date pattern
  • D: Long date pattern
  • t: Short time pattern
  • T: Long time pattern
  • F: Full date/time pattern (long time)
  • m or M: Month day pattern
  • s: Sortable date/time pattern
  • y or Y: Year month pattern
- the standard format strings: f, F, g, G, O, o, R, r, u, U are not supported. However, custom format strings that use the “mmm”, “yyyy”, “hh”, etc. formats are supported. You can build your own date format string.

http://seejoelprogram.wordpress.com/2008/08/07/supported-number-and-datetime-format-strings-in-aspnet-ajax/




Kaip iš DateTime gauti datos formatą JavaScript'e:

DateAdded: (new Date(parseFloat(result.d[i].auditdate.slice(6, 19)))).localeFormat("d")

čia 6,19 iš DateTime formato nuima pradžią ir pabaigą.

2013 m. rugsėjo 11 d., trečiadienis

JQuery UI: Dialog savybė AppendTo

Problema: sukūrėme dialogo langą su JQuery dialog. Dialogo lange yra checkbox. Pakeitus checkbox reikšmę, langas užsidaro ir visas puslapis persikrauna.

Sprendimas: naudoti appendTo savybę. Tam reikia visą HTML kodą, kuriame aprašytas dialogas, įdėti į papildomą div elementą ir to div ID nurodyti AppendTo.

JQuery:

 $(document).ready(function () {

            $("#dvOrder").dialog({
                appendTo: "#dvContainer",
                autoOpen: false,
                modal: true,
                width: 800,
                height: 320,
                resizable: false,
                title: "Užsakymo patvirtinimas",
                buttons: [
                    {
                        text: "Tvirtinti",
                        click: function () {
                            SSService.ConfirmOrder(document.getElementById("txtDate").value, document.getElementById("ddlHours").value, document.getElementById("ddlMin").value, document.getElementById("tbPlaceFrom").value, document.getElementById("tbPlaceTo").value, document.getElementById("tbNameSurname").value, $('#cbMeet').val(),$('#tbInfo').val(), $('#tbInfo2').val(), document.getElementById("hfOrderID").value, function (result) {
                                if (result) {

                                    var rowID = document.getElementById("hfrowID").value

                                    if (rowID != "") {
                                        var oTR = $("#" + rowID).get(0);
                                        oTR.cells[0].innerText = "";
                                        if ((result.MeetDate + " " + result.MDHours + " : " + result.MDMin).trim != ":") {
                                            oTR.cells[2].innerText = result.MeetDate + " " + result.MDHours + " : " + result.MDMin;
                                        };
                                        oTR.cells[3].innerText = result.MeetFrom;
                                        oTR.cells[4].innerText = result.MeetTo;
                                        oTR.cells[5].innerText = result.NameSurname;
                                        oTR.cells[6].innerText = result.MeetInAirport;
                                        oTR.cells[7].innerText = result.FlightFrom;
                                        oTR.cells[8].innerText = result.Note;
                                        oTR.cells[10].innerText = result.Status;
                                        oTR.cells[11].innerText = result.TaxiOrderNo;
                                    };
                                };
                            });


                            $(this).dialog("close");
                        }
                    },
                    {
                        text: "Atmesti",
                        click: function () {

                         //kodas
                        }
                    }
                ],
                open: function () {
                    document.getElementById("tbPlaceFrom").focus();
                }
            });

         

        });


HTML kodas:
< div id = "dvContainer" >
        < div id="dvOrder" style="display: none" >
         
        < / div >
  < / div >
       

2013 m. rugsėjo 10 d., antradienis

CustomValidator pavyzdys su VB ASP.NET

Užduotis: jeigu CheckBox pažymėtas varnele, privaloma užpildyti dar du laukus: tbInfo ir tbInfo2


                             
ID="cvMeet" runat="server"
ErrorMessage="Privalomas"
OnServerValidate="cvMeet_ServerValidate"
ValidateEmptyText="True"
ClientValidationFunction="validateTaxiOrderForm" ForeColor="Red">


JavaScript:

function validateTaxiOrderForm ( source, args) {
            if ($("#cbMeet").val() == "checked"
                && $("#tbInfo").val() == ""
               && $.trim($("#tbInfo2").val()) == "") {

                args.IsValid = false;
            } else {
                args.IsValid = true;
                window.returnValue = true;
            };

        };

VB:
Protected Sub cvMeet_ServerValidate(source As Object, args As ServerValidateEventArgs) Handles cvMeet.ServerValidate
        If cbMeet.Checked = True Then
            Validate("meet")
            If Not IsValid Then
                Return
            End If
        End If
    End Sub

Client-side valdidavimą galima išjungti su savybe EnableClientScript=false

2013 m. rugpjūčio 23 d., penktadienis

Understanding RegisterClientScriptBlock and RegisterStartupScript

RegisterClientScriptBlock - įterpia javascript tekstą prieš formuojant HTML(nenaudojamas dirbant su UpdatePanel, nes scriptų neužregistruoja).

RegisterStartupScript - įterpia javascript tekstą jau suformavus HTML elementus (naudojama inicializacijai ir dirbant su UpdatePanel).

Partial Class Default2
    Inherits System.Web.UI.Page

    Protected Sub Page_PreRender(sender As Object, e As EventArgs) Handles Me.PreRender
        Dim sScript As String = "" &
            "function checkBox() {" &
            "   if (document.getElementById('" + TextBox1.ClientID + "').value != 'OK') {alert('Wrong'); return false} else {return true};" &
            "};"
        ScriptManager.RegisterClientScriptBlock(Me, Me.GetType, "tt", sScript, True)

        Button1.Attributes.Add("onclick", "return checkBox();") - užregistruoja, kada turi būti iškviečiama javascript funkcija

        ScriptManager.RegisterStartupScript(Me, Me.GetType(), "ttt", "document.getElementById('" + TextBox1.ClientID + "').value = '" & Now().ToString() & "';", True)
    End Sub

    Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Literal1.Text = Now()
    End Sub
End Class

Pagal tokį kodą, HTML suformuojamas taip:


2013 m. rugpjūčio 18 d., sekmadienis

How to call web service synchronously with JavaSript in ASP.NET

 function gvUpdateHeader(sUserLang) {
            var gv = document.getElementById("gvsummary");

            if (gv != null) {
             
                var strid = 2;

                for (var i = 1; i < gv.rows[0].cells.length; i++) {
                    getStringByLang(sUserLang, strid, i, gv);
                    strid++;
                }

            };

        };

        function getStringByLang(sUserLang, strid, i, gv) {

            VIService.GetString(sUserLang, strid, function (result) {
                if (result) {

                    gv.rows[0].cells[i].innerHTML = result;
                };
            });
        }