Reputation: 517
I currently have a VB.Net application that builds textboxes dynamically.
I need to display a button control which will display a datepicker and then populate the corresponding textbox with the selected date value.
I am creating the btnCalendar dynamically since there are more than one calendar buttons on a particular page, so btnCalendar.ID = tab.ID & grdRowID
Protected Sub DisplaySearchWindow()
Dim ddl As DropDownList
Dim txt As TextBox
Dim cal As Calendar
Dim btnCalendar As Button
Select Case iIndex
Case 1
Dim cv As New CompareValidator
txt = New TextBox
txt.ID = "txt" & UserName & grdRowID.Name
cv.ControlToValidate = txt.ID
btnCalendar = New Button
btnCalendar.ID = "btnCalDisplay" & tab.ID & grdRowID
btnCalendar.Text = "+"
btnCalendar.ToolTip = "click to view calendar"
btnCalendar.Attributes.Add("OnClientClick", "javascript:return ShowAlert('Hi');")
c.Controls.Add(cv)
c.Controls.Add(txt)
c.Controls.Add(btnCalendar)
When building the button control in codebehind, I have btnCalendar.OnClientClick = btnCalendar.Visible = True
When I run the application and click btnCalendar, I get an error message JavaScript runtime error: 'True' is undefined.
How can I display the DatePicker control using btnCalendar.OnClientClick (or any other alternative) from codebehind ?
Upvotes: 1
Views: 1180
Reputation: 3746
If you are open to an alternative (which from your post, you indicate so), you can try this:
Select Case iIndex
Case 1
Dim cv As New CompareValidator
txt = New TextBox
txt.ID = "txt" & UserName & grdRowID.Name
txt.cssclass="DateValue"
cv.ControlToValidate = txt.ID
c.Controls.Add(cv)
c.Controls.Add(txt)
Then on your aspx page, follow the example on the JQueryUI page:
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.1/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.1/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">
<script>
$(function() {
$( "#datepicker" ).datepicker();
});
</script>
Upvotes: 2
Reputation: 343
In your code behind the code should be:
Sub btnCalendar_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCalendar.Click
btnCalendar.Visible = True
end sub
or you can try this in your asp page:
<%@ page language="VB"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Sub btnCalendar_Click(ByVal sender As Object, ByVal e As System.EventArgs)
btnCalendar.Visible = True
End Sub
</script>
<html>
<head>
</head>
<body>
<form id="form1" runat="server">
<asp:button id="btnCalendar" runat="server" onclick="btnCalendar_Click" />
</form>
</body>
</html>
Upvotes: 0