 |
|
สอบถามเกี่ยวกับการเก็บ dropdown value ใน cookies ครับ |
|
 |
|
|
 |
 |
|
Cookies มันจะต้อง Refresh ก่อน 1 ครั้งครับ ถึงจะอ่านค่าได้ครับ 
|
 |
 |
 |
 |
Date :
2016-11-24 18:06:13 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
วิธีแก้ไขทำเป็น Class (นิสัย) เก็บเอาไว้ (หลบหลีก Events PostBack/Not PostBack)
Code (VB.NET)
Imports System.Web
Imports System.Collections
Imports System.Collections.Specialized
Imports System.Web.Security 'Add Referance System.Web.Extentions
Public Class myCookies
Private Shared _Current As HttpContext = HttpContext.Current
Private Shared _cookieName As String = "__หน้าฮี__"
Private Shared _data As HybridDictionary = Nothing
Sub New()
End Sub
Sub New(ByVal cookieName As String)
_cookieName = cookieName
End Sub
Public Sub InsertValue(ByVal subKey As String, ByVal subValue As String)
If _Current.Response.Cookies(_cookieName) IsNot Nothing Then
Dim aCookie As HttpCookie = _Current.Response.Cookies(_cookieName)
aCookie.Values.Add(subKey, subValue)
Else
Dim aCookie As New HttpCookie(_cookieName)
aCookie.Values.Add(subKey, subValue)
_Current.Response.AppendCookie(aCookie)
End If
End Sub
Public Function GetValue(ByVal subKey As String) As String
Dim retValue As String = String.Empty
If _Current.Response.Cookies(_cookieName) IsNot Nothing Then
Dim aCookie As HttpCookie = _Current.Response.Cookies(_cookieName)
Try
retValue = aCookie.Values(subKey)
Catch ex As Exception
'Throw ex
End Try
End If
Return retValue
End Function
''' <summary>
''' Modify subKey and subValue
''' </summary>
''' <param name="subKey"></param>
''' <param name="subValue"></param>
''' <returns>True/False</returns>
''' <remarks>If subKey not exists recrete new</remarks>
Public Function ModifyValue(ByVal subKey As String, ByVal subValue As String) As Boolean
Dim suc As Boolean = False
If _Current.Request.Cookies(_cookieName) IsNot Nothing Then
Try
_Current.Request.Cookies(_cookieName)(subKey) = subValue
suc = True
Catch ex As Exception
Try
InsertValue(subKey, subValue)
suc = True
Catch ex1 As Exception
Throw ex1
End Try
End Try
End If
Return suc
End Function
Public Sub Save()
' Setting a cookie's value and/or subvalue using the HttpCookie class
Dim cookie As HttpCookie
If _Current.Request.Cookies(_cookieName) IsNot Nothing Then
_Current.Request.Cookies.Remove(_cookieName)
End If
cookie = New HttpCookie(_cookieName)
If _data.Count > 0 Then
Dim cookieData As IEnumerator = _data.GetEnumerator()
Dim item As DictionaryEntry
While cookieData.MoveNext()
item = CType(cookieData.Current, DictionaryEntry)
cookie.Values.Add(item.Key.ToString(), item.Value.ToString())
End While
End If
_Current.Response.AppendCookie(cookie)
End Sub
Public Sub Delete()
' Set the value of the cookie to null and set its expiration to some time in the past
If _Current.Response.Cookies(_cookieName) IsNot Nothing Then
_Current.Response.Cookies(_cookieName).Value = Nothing
' last month
_Current.Response.Cookies(_cookieName).Expires = System.DateTime.Now.AddMonths(-1)
End If
End Sub
Public Sub Delete(ByVal subKey As String)
' Set the value of the cookie to null and set its expiration to some time in the past
If _Current.Response.Cookies(_cookieName) IsNot Nothing Then
Dim aCookie As HttpCookie = _Current.Request.Cookies(_cookieName)
aCookie.Values.Remove(subKey)
aCookie.Expires = DateTime.Now.AddDays(-1)
_Current.Response.Cookies.Add(aCookie)
End If
End Sub
''' <summary>
''' Reading Cookie Collections
''' </summary>
''' <remarks></remarks>
Public Function ReadingCookieCollections() As String
Dim output As System.Text.StringBuilder = New System.Text.StringBuilder()
Dim aCookie As HttpCookie
Dim subkeyName, subkeyValue As String
For i As Integer = 0 To _Current.Request.Cookies.Count - 1
aCookie = _Current.Request.Cookies(i)
output.Append("Name = " & aCookie.Name & "<br />")
If aCookie.HasKeys Then
Dim CookieValues As System.Collections.Specialized.NameValueCollection = aCookie.Values
Dim CookieValueNames() As String = CookieValues.AllKeys
For j As Integer = 0 To CookieValues.Count - 1
subkeyName = _Current.Server.HtmlEncode(CookieValueNames(j))
subkeyValue = _Current.Server.HtmlEncode(CookieValues(j))
output.Append("Subkey name = " & subkeyName & "<br />")
output.Append("Subkey value = " & subkeyValue & "<br /><br />")
Next
Else
output.Append("Value = " & _Current.Server.HtmlEncode(aCookie.Value) & "<br /><br />")
End If
Next
Return output.ToString()
End Function
End Class
ปล. ยัดเงินใส่กระเป๋าให้หนึ่งกำมือ คงไม่ต้องบอกว่าจะใช้เงินอย่างไร?น่ะ
|
 |
 |
 |
 |
Date :
2016-11-25 09:22:26 |
By :
หน้าฮี |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
จาก #No 2 ลืมบอกไปว่า "สูงสุดคืนสู่สามัญ"
หมายควยว่า "ใช้ HTML ธรรมดาฯ" นี่แหละในการสร้างสรรค์ผลงาน
Code (XML)
<select>
<option value="หน้า">1</option>
<option value="ฮี">2</option>
<option value="หอย">3</option>
<option value="งาม">4</option>
</select>
พ่อเอ็งชื่อ: <input type="text" name="faName" id="faName">
แม่เอ็งชื่อ: <input type="text" name="MaName" id="MaName">
...
...
...
|
 |
 |
 |
 |
Date :
2016-11-25 09:40:00 |
By :
หน้าฮี |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
จาก #NO 3 สาระสำคัญของ เวป ก็คือ Server/Client
พยายามจะบอกว่า อะไรที่ทำที่เครื่อง Client ได้ก็ต้องทำ (แน่นอนว่า มีได้/มีเสีย)
--- แต่ข้อดีมีมากกว่า อทิเช่น ความเร็วปรุ๊ดปร๊าดฯ ตอบสนองทันทีทันใด
--- ข้อเสียมันก็พอฯกับปิดไฟจับหอยเมีย (...)
โค๊ดข้างล่างนี้คือโค๊ดที่ผมหัดเขียน JavaScript/Jquery
--- รู้อะไรก็ให้มันรู้จริง
Code (JavaScript)
function divSetActiveView(divChild, vwID) {
for (var i = 0; i < divChild.length; i++) {
if (divChild[i].id == vwID) {
divChild[i].style.display = "block";
} else {
divChild[i].style.display = "none";
}
//}
}
}
//ใช้แทน GridView Server Control
function InitialDataTable(tableName) {
var this_selected = [];
$(function () {
var objTable = $('#' + tableName).DataTable({
responsive: true,
lengthChange: false, //Page Size
searching: true, //Search Box
bProcessing: true, //Progress
bFilter: false,
pagingType: "full_numbers",
autoWidth: true,
bServerSide: true,
sAjaxSource: 'หน้าฮี WCF',
sServerMethod: 'post',
stateSave: false,
"columnDefs": [
{
"targets": [5],
"searchable": false,
"sortable": false,
"className": "dtCell_center",
"render": function (data, type, row) {
return '<input type="checkbox" class="checkboxes" value="' + data + '" />';
}
}
],
"fnInitComplete": function (oSettings, json) {
$('.dataTables_filter').hide();
},
"rowCallback": function (row, data) {
if ($.inArray(data[5], this_selected) !== -1) {
//var rowNumber = objTable.rows({ order: 'applied' }).nodes().indexOf($(row));
$(row).addClass('selected');
}
},
"fnCreatedRow": function (nRow, aData, iDataIndex) { // Create tr id='XXX'
$(nRow).attr('id', aData[5]);
},
"fnDrawCallback": function () {
if (this.fnSettings() !== null) {
if (Math.ceil((this.fnSettings().fnRecordsDisplay()) / this.fnSettings()._iDisplayLength) > 1) {
$('.dataTables_paginate').css("display", "block");
} else {
$('.dataTables_paginate').css("display", "none");
}
}
}
});
function search(force) {
var objSearch = $('#_txtSearch');
var strSearch = $('#_txtSearch').val();
if (!force && strSearch.length < 2) return; //wasn't enter, not > 1 char
objTable.search(strSearch).draw();
//More detail TestLargeRows.aspx
//ทดสอบดึงข้อมูล 1 ล้านระเบียนผ่านเวป
}
$(document).on('keyup', '#txtSearchXXX', function (event) {
clearTimeout($.data(this, 'timer'));
if (event.keyCode == 13 || event.which == 13) { //e.which = Browser FireFox
search(true);
} else {
$(this).data('timer', setTimeout(search, 3000)); //1000 ms x s วินาที
}
});
$(document).on('click', '#_ButtonSearchStd', function (event) {
var objSearch = $('#_txtSearch');
var strSearch = objSearch.val();
objTable.search(strSearch).draw();
//objTable.draw();
});
$("#" + tableName + " thead tr th").resizable({
handles: 'e'
});
$(document).on("dblclick", "#" + tableName + " tbody tr", function () {
//ลบแถว
//objTable.row('.selected').remove().draw(false);
//var rowData = objTable.row(this).data(); //น่าสนใจ
var ref = $(this).find('td:eq(0)').text(); //$(this).find('td:first').text();
if (ref) {
showMessageBox(ref);
}
});
// Retain selection on reload (Multiple Selected/Single Selected)
$('#' + tableName + ' tbody').on('click', 'tr', function () {
this_selected.length = 0; //Clear Array
objTable.$('tr.selected').removeClass('selected');
this_selected.push(this.id); //Add a new item to an array (Append mode)
$(this).toggleClass('selected');
});
});
}
|
 |
 |
 |
 |
Date :
2016-11-25 10:09:49 |
By :
หน้าฮี |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ใช้ปืนฆ่าคนได้ย่อมใช้ดาบฆ่าคนได้เช่นเดียวกัน
อันนี้ทำไปเรื่อยฯ ไม่มีกำหนดเสร็จสมบูรณ์
Windows Calendar User Control (รองรับ Calture เช่น th-TH, en-US, en-GB)

อันนี้เขียนเล่นฯ ยังไม่ได้ข้อสรุป (วันนั้นเกิดเบื่อโลกขึ้นมา)
Code (VB.NET)
Private Function findDMY(ByVal txt As String, Optional ByVal dmy As String = "m") As String
Dim strMonthRet As String = ""
For i As Integer = 0 To txt.Length - 1
If (_Mask(i).ToString()).ToLower() = dmy.ToLower() Then
strMonthRet &= txt.Substring(i, 1)
End If
Next
strMonthRet = If(strMonthRet = "", "0", strMonthRet) 'CInt(If(strMonthRet = "", "0", strMonthRet)) '.ToString("D2") 'Padding zero 01, 02, ..., 12
Return strMonthRet '1-31, 01-31, 1-12, 01-12
End Function
Protected Overrides Sub OnKeyPress(ByVal e As System.Windows.Forms.KeyPressEventArgs)
If AscW(e.KeyChar) = Keys.Back OrElse AscW(e.KeyChar) = Keys.Delete OrElse AscW(e.KeyChar) = Keys.Left OrElse AscW(e.KeyChar) = Keys.Right Then
e.Handled = False
Return
End If
If Mask <> "" Then
e.Handled = True
Dim newText As String = Me.Text
Dim Finished As Boolean = False
Dim lstMaxDays As String() = {"31", "28", "31", "30", "31", "30", "31", "31", "30", "31", "30", "31"}
For i As Integer = Me.SelectionStart To _Mask.Length - 1
Select Case (_Mask(i).ToString()).ToLower()
Case "d"
If (Char.IsDigit(e.KeyChar)) Then
newText &= e.KeyChar.ToString()
Dim getDay As String = findDMY(newText, "d")
If (getDay.Length = 0 AndAlso e.KeyChar > "3") OrElse (getDay.Length = 2 AndAlso newText = "3" AndAlso e.KeyChar > "1") Then
Return
ElseIf CInt(getDay) > 31 OrElse getDay = "00" Then
Return
End If
'If CInt(getDay) > 31 OrElse getDay = "00" Then
' Return
'End If
Finished = True
Else
Return
End If
Case "m"
If (Char.IsDigit(e.KeyChar)) Then
newText &= e.KeyChar.ToString()
Dim getMonth As String = findDMY(newText, "m")
If CInt(getMonth) > 12 OrElse getMonth = "00" Then
Return
End If
Finished = True
Else
Return
End If
Case "y"
If (Char.IsDigit(e.KeyChar)) Then
newText &= e.KeyChar.ToString()
Finished = True
Else
Return
End If
Case Else 'Mask symbol.
newText &= _Mask(i)
End Select
If Finished Then
Exit For
End If
Next
'Update the Text.
Me.Text = newText
Me.SelectionStart = Me.Text.Length
End If
End Sub
ปล. คิดได้หมดร้อยแปดพันเก้าแต่ไม่มีเวลาทำ
|
 |
 |
 |
 |
Date :
2016-11-25 10:25:52 |
By :
หน้าฮี |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณมากครับ
|
 |
 |
 |
 |
Date :
2016-11-25 13:18:10 |
By :
kornraphat |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อยากทำต่อให้สมบูรณ์แต่ไม่มีเวลา (ขี้เกียจแล้วว่ะเฮ้ย)
Code (VB.NET)
Imports System.Drawing
Imports System.Windows.Forms
'
<ToolboxBitmap(GetType(TextBox))> _
Public Class usrCtrlMaskTextBox : Inherits TextBox
#Region " Private Variables "
Private WithEvents _DTP As New DateTimePicker 'เอาไว้กันเหนียว (เรื่องอะไรตูจะไปคำนวณด้วยตัวเอง +55555)
Private _Mask As String 'กำหนดได้ตามใจชอบเช่น "ไก่งามเพราะขนคนงามเพราะหอย"
Private _Button As New Button() With {.Text = String.Empty} 'ปุ่มแสดงวันที่ให้เลือก
#End Region
#Region " Properties "
<System.ComponentModel.DefaultValue(GetType(String), "Text"), System.ComponentModel.Category("Appearance")> _
Public Property Mask() As String
Get
Return _Mask 'เช่น หำMM/dd/yyyy, yyyy/หำdd/MM, etc... รองรับทุกรูปแบบ
End Get
Set(ByVal value As String)
_Mask = value
End Set
End Property
Private mKey As String
<System.ComponentModel.DefaultValue(GetType(String), "Text"), System.ComponentModel.Category("Appearance")> _
Public Property _Key() As String
Get
Return mKey
End Get
Set(ByVal value As String)
mKey = value
End Set
End Property
#End Region
#Region " Constructor "
Public Sub New()
AddHandler _Button.Click, Sub(หอย, งาม)
'
'Display Date Dialog.
'
End Sub
End Sub
#End Region
Protected Overrides Sub OnKeyDown(e As KeyEventArgs)
'MyBase.OnKeyDown(e)
'e.Handled = True
End Sub
Private Function findDMY(ByVal txt As String, Optional ByVal dmy As String = "m") As String
Dim strRet As String = ""
For i As Integer = 0 To txt.Length - 1
If (_Mask(i).ToString()).ToLower() = dmy.ToLower() Then
strRet &= txt.Substring(i, 1)
End If
Next
Return If(strRet = "", "0", strRet)
End Function
''' <summary>
''' ตรวจสอบเดือนกุมภาพันธ์มี 29 วันหรือไม่?
''' Dim isLeap As Boolean = isLeapyear(2000)
''' </summary>
''' <param name="shrYear"></param>
''' <returns></returns>
''' <remarks></remarks>
Private Function isLeapyear(ByVal shrYear As Short) As Boolean
Return Date.IsLeapYear(shrYear)
End Function
Protected Overrides Sub OnKeyPress(ByVal e As System.Windows.Forms.KeyPressEventArgs)
If AscW(e.KeyChar) = Keys.Back OrElse AscW(e.KeyChar) = Keys.Delete OrElse AscW(e.KeyChar) = Keys.Left OrElse AscW(e.KeyChar) = Keys.Right Then
e.Handled = False
Return
End If
If Mask <> String.Empty Then
e.Handled = True
Dim newText As String = Me.Text
Dim Finished As Boolean = False
Dim daysInMonth = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
Dim mask1 As String = String.Empty
For i As Integer = Me.SelectionStart To _Mask.Length - 1
mask1 = _Mask(i).ToString().ToLower()
If Not (Char.IsDigit(e.KeyChar)) Then
Return
Else
If "dmy".Contains(mask1) Then
newText &= e.KeyChar.ToString()
Finished = True
Else 'Mark symbol
newText &= mask1
Finished = False
End If
End If
Select Case mask1
Case "d"
Dim getDay As String = findDMY(newText, "d")
'ป้องกันการป้อนวันที่ >= 31 และ 00
If (CByte(getDay) > 31) OrElse (getDay.Length = 1 AndAlso e.KeyChar > "3") OrElse (getDay.Length > 1 AndAlso getDay.Substring(0, 2) = "00") Then
Return
End If
Case "m"
Dim getDay As String = findDMY(newText, "d")
Dim getMonth As String = findDMY(newText, "m")
'ป้องกันการป้อนเดือน > 12 และป้อนเดือน 00
If CByte(getMonth) > 12 OrElse (getMonth.Length > 1 AndAlso getMonth.Substring(0, 2) = "00") Then
Return
End If
'ป้อนเดือน 01 - 09 หรือ 1 - 9
If CByte(getMonth) > 0 Then
Dim lastDayOfMonth As Byte = daysInMonth(getMonth - 1)
If CByte(getDay) > lastDayOfMonth Then
Return
End If
If getMonth.Length = 1 AndAlso CByte(getMonth) <> 1 Then
getMonth = "0" & getMonth
'ตั้งใจทำ พิมพ์ 2 --> 02, 3 --> 03, 9 -->09 เป็นต้น แต่ขี้เกียจทำแล้ว
End If
ElseIf getMonth.Length > 1 AndAlso getMonth.Substring(0, 2) = "00" Then
Return
End If
Case "y"
Dim getDay As String = findDMY(newText, "d")
Dim getMonth As String = findDMY(newText, "m")
Dim getYear As String = findDMY(newText, "y")
If Not isLeapyear(CShort(getYear)) Then
daysInMonth(1) = 28 'เดือนกุมภาพันธ์มี่ 28 วัน
End If
'
'ตรวสอบปีที่ป้อน เดือนกุมพาพันธ์มี 29 วันหรือไม่?
'ขี้เกียจทำแล้วว่ะเฮ้ย
'
End Select
If Finished Then
Exit For
End If
Next
'Update the Text.
Me.Text = newText
Me.SelectionStart = Me.Text.Length
End If
End Sub
Protected Overrides Sub OnValidating(ByVal e As System.ComponentModel.CancelEventArgs)
'ยังไม่ได้ทำและขี้เกียจทำ
End Sub
Public Sub ResetValue()
MyBase.Text = String.Empty
End Sub
Protected Overrides Sub OnCausesValidationChanged(e As EventArgs)
MyBase.OnCausesValidationChanged(e)
End Sub
End Class
|
 |
 |
 |
 |
Date :
2016-11-25 15:30:22 |
By :
หน้าฮี |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
จาก #NO7 บรรทัดที่ 57 ต้องตรวจสอบเพิ่มเติมดังนี้
Code (VB.NET)
If Array.IndexOf(_Mask, i) <> -1 Then
If (_Mask(i).ToString()).ToLower() = dmy.ToLower() Then
strRet &= txt.Substring(i, 1)
End If
End If
ปล. ความเป็นศิลปินโปรแกรมเมอร์มันแตกต่างกัน
|
 |
 |
 |
 |
Date :
2016-11-25 15:49:08 |
By :
หน้าฮี |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|