REM Handling Auto Current Date Insert in FV Insert
REM Adding guiding text again after removing it for inserting
Dim tmp_Date_of_EntryTextBox As TextBox
tmp_Date_of_EntryTextBox = CType(FormView1.FindControl("Date_of_EntryTextBox"), TextBox)
If FormView1.CurrentMode = FormViewMode.Insert Then
tmp_Date_of_EntryTextBox.Text = "Type 'd' to enter Today's Date..."
End If
In Formview1.Databound()
REM Handling Auto Current Date Insert in FV Insert
REM Adding guiding text to textbox
If FormView1.CurrentMode = FormViewMode.Insert Then
Dim tmp_Date_of_EntryTextBox As TextBox
tmp_Date_of_EntryTextBox = CType(FormView1.FindControl("Date_of_EntryTextBox"), TextBox)
tmp_Date_of_EntryTextBox.Text = "Type 'd' to enter Today's Date..."
End If
REM Handling Auto Current Date Insert in FV Insert
If FormView1.CurrentMode = FormViewMode.Insert Then
Dim tmp_Date_of_EntryTextBox As TextBox
tmp_Date_of_EntryTextBox = CType(FormView1.FindControl("Date_of_EntryTextBox"), TextBox)
REM Clearing guiding text in textbox on FIRST focus
REM Adding javascript onfocus and changing value to Nothing in textbox
REM Using ternary operator to see if guiding text is present, then clear it, else not.
tmp_Date_of_EntryTextBox.Attributes.Add("onfocus", "javascript:((this.value == 'Type \'d\' to enter Today\'s Date...') ? (this.value = '') : (null));")
REM Adding javascript onkeyup and changing value to current date in textbox through ShowTime() function defined in aspx
REM Using ternary operator to see if key pressed is 'd', then insert current date, else not.
tmp_Date_of_EntryTextBox.Attributes.Add("onkeyup", "javascript:((this.value == 'd') ? (this.value = ShowTime()) : (null));")
REM Adding javascript onblur (lost focus) and changing value to guiding text if textbox is empty, else not.
tmp_Date_of_EntryTextBox.Attributes.Add("onblur", "javascript:((this.value == '') ? (this.value = 'Type \'d\' to enter Today\'s Date...') : (null));")
End If
In Insertbutton.click()
REM Handling Auto Current Date Insert in FV Insert
REM Checking if guiding text is present and if so, removing it before insert
If FormView1.CurrentMode = FormViewMode.Insert Then
Dim tmp_Date_of_EntryTextBox As TextBox
tmp_Date_of_EntryTextBox = CType(FormView1.FindControl("Date_of_EntryTextBox"), TextBox)
If tmp_Date_of_EntryTextBox.Text = "Type 'd' to enter Today's Date..." Then
tmp_Date_of_EntryTextBox.Text = ""
End If
End If
In .aspx <head>
<head runat="server">
<link href="Gridview_StyleSheet.css" rel="stylesheet" type="text/css" />
<title>Lungar Project Online Portal</title>
<link rel="SHORTCUT ICON" href="~/Images/favicon.ico" />
<script type="text/javascript">
function ShowTime() {
// REM Handling Auto Current Date Insert in FV Insert
var dt = new Date();
var d = "0"
var m = "0"
var y = "0"
// Converting month to MMM format and assigning it to variable
if (dt.getMonth() == "0")
{
var m = "Jan"
}
if (dt.getMonth() == "1")
{
var m = "Feb"
}
if (dt.getMonth() == "2")
{
var m = "Mar"
}
if (dt.getMonth() == "3")
{
var m = "Apr"
}
if (dt.getMonth() == "4")
{
var m = "May"
}
if (dt.getMonth() == "5")
{
var m = "Jun"
}
if (dt.getMonth() == "6")
{
var m = "Jul"
}
if (dt.getMonth() == "7")
{
var m = "Aug"
}
if (dt.getMonth() == "8")
{
var m = "Sep"
}
if (dt.getMonth() == "9")
{
var m = "Oct"
}
if (dt.getMonth() == "10")
{
var m = "Nov"
}
if (dt.getMonth() == "11")
{
var m = "Dec"
}
// Getting day and assigning it to variable
d = dt.getDate()
// Getting full year and assigning it to variable
y = dt.getFullYear()
// Returning back to Formview1.databound()
return d + " " + m + " " + y
}
</script>
</head>
Method below works but causes problems due to autopostback in textbox which causes the button to be pressed twice to work
No comments:
Post a Comment