RadDatePicker in RadGrid - asp.net

I'm using Telerik RadGrids and I have RadDatePickers for columns with type of DateTime. However, when I want to pick a date it doesn't work at all. No errors, but it's simply not working. I've noticed that strangely I could select more days, but I want to be able to select a single day by clicking once on the given day.
I've observed that when clicking on the previous/next month I can select a day exactly as I would like, so there is a hack which might work (in my research it worked perfectly after the first postback, but before the first postback it didn't work at all):
Public Sub PageInit(ByVal sender As Object, ByVal e As
System.EventArgs)
Me.Page.ClientScript.RegisterStartupScript(GetType(TTControls.TTAjaxState),
"Page_Init_" & Me.UniqueID, "if (!(hasEndRequest)) var hasEndRequest =
false; if (!(hasEndRequest)) {var prm =
Sys.WebForms.PageRequestManager.getInstance();prm.add_endRequest(function()
{$('.rcPrev').click();console.log('clicked');});} hasEndRequest =
true;", True)
End Sub
In the code above you can see a method which will be a handler for page init.
However, I would very much like to be able to select a day by clicking on the RadDatePicker and clicking on a day. Here is how my RadDatePicker looks like:
If anybody knows the solution and decides to share it with me (if the solution is not a hack then I would be extremely happy) I would be very gladful.
Thank you in advance,
Lajos Árpád.

Will it demand a lot of work to replace your RadDateTimePicker by a RadCalendar?
The RadCalendar supports the property SelectionMode..

Have you set the SelectionMode property to Single?

Solution:
Sys.Application.add_load(function () {
$(".RadCalendar.RadCalendar_Default .rcPrev").each(function () { $(this).click(); });
});

Related

Button.Enabled and checkbox.Checked status erased when redirecting on event ASP.NET VB

In my register page I have a checkbox (chkAgree) next to the terms of agreement. The register (btnRegister) button is disabled until chkAgree.Checked = True. Since the registration section is toward the bottom of the page I want to redirect the user to an anchor tag during the event. I can't seem to accomplish this without one of the two objects in question losing their status. I tried creating a Session for each object and then calling them on the page load event with no luck. I am obviously doing it wrong, but could someone please point me in the right direction? btnRegister's default status is set to Enabled=False. Here are the two methods I am using
CheckedChanged:
Protected Sub chkAgree_CheckedChanged(sender As Object, e As EventArgs) Handles chkAgree.CheckedChanged
Session("Agree") = chkAgree.Checked
Response.Redirect("~/ExteriorStudentTestimonials.aspx#register", False)
End Sub
And Page_Load:
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Session("Agree") = True Then
btnRegister.Enabled = True
chkAgree.Checked = True
Else
btnRegister.Enabled = False
chkAgree.Checked = False
End If
End Sub
I have tried several different combinations of If statements but cannot figure it out without taking Response.Redirect("~/ExteriorStudentTestimonials.aspx#register", False) out.
This might be related to the fact that you're reloading the page. You might want to take a look at the following question for some ideas of how to jump to an anchor without a full redirect: Programmatically scroll to an Anchor Tag
On a different note, jumping to an anchor when the user clicks a check box doesn't sound like a very good user experience. You might consider making your form shorter.
Got it using this method similar to the ones described in the link you provided
Page.ClientScript.RegisterStartupScript(Page.GetType(),
"navigate",
"document.getElementById('register').scrollIntoView();",
True)

Having issues with the .Visible property of a text box

I'm working on a web application where a user can order a custom portrait drawings by making choices from a variety of radio button lists. There is an extra charge if they want multiple people in the portrait, so one of the questions is whether or not there will be an additional person. They can select either "Yes" or "No" from a radio button list (the choices are currently in that order, with Yes at index 0 and No at index 1). If the user selects No, nothing happens and they move on to the next question. But if they click yes, a text box whose Visible property is currently set to False appears and they enter the number of additional people.
The problem is that I can't get my text box to become visible. I currently have my TextBox.Visible = True line of code under the radio button list's SelectedIndexChanged event handler. Here's the whole subroutine:
Protected Sub RadioButtonListAdditional_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles RadioButtonListAdditional.SelectedIndexChanged
Dim characters As Integer
If RadioButtonListAdditional.SelectedIndex = 0 Then
txtAdditionalChars.Visible = True
characters = CInt(txtAdditionalChars.Text)
additionalprice = characters * 5
ElseIf RadioButtonListAdditional.SelectedIndex = 1 Then
additionalprice = 0
End If
End Sub
additionalprice was declared earlier. The rest of that just has to do with the pricing scale for the additional characters. Anyway, I feel like I'm really close to having it right and that I'm just missing something small - my VB is a little bit rusty. Any suggestions?
Have you set AutoPostBack = True on your RadioButtonListAdditional object?
Or you may need to check whether you have code on Page_Load event that call
txtAdditionalChars.Visible = False
Please let me know if this helps
In VB Net .. Radiobutton control ..
Do it in your Radiobutton CheckedChanged event .. something like this
if rb.Checked then txtbox.Visible = True

Can I start the Calendar Control for asp.NET to be a future date?

I need to have the Calendar Control start 36 hours after the current date. How would I do that?
I have a form that requires that the future date has to be at least 36 hours from the current date in the order for the workers involved to be able to complete the task.
EDIT: Thanks everyone for helping with my question. I've created a solution that will allow me to check values and keep the form from processing:
Protected Sub calPickupDate_SelectionChanged(sender As Object, e As System.EventArgs) Handles calPickupDate.SelectionChanged
If calPickupDate.SelectedDate < Today.AddHours(36) Then
ASPNET_MsgBox("You must leave at least 36 hours for procesing of your order.")
txtPickupDate.Text = ""
Else
txtPickupDate.Text = calPickupDate.SelectedDate.ToString("MM/dd/yyyy")
End If
End Sub
So, how do I close out the question?
Dim DateTimePicker As New DateTimePicker
DateTimePicker.MinDate = Date.Now.AddHours(36)
DateTimePicker.Value = Date.Now.AddHours(36)
add below code on your form load.
calPickupDate.MinDate = Date.Now.AddHours(36)
hope this will help you.
I assume you mean a date picker type of "calendar" and not a calendar. If so, you are dealing with a data validation issue.
There are different ways to validate the input. The quickest is server side only. If the user picks the wrong date, you tell him and he can pick ad nauseum until he gets a clue. Not the best UI, but it works.
Since the data ends up in a textbox, you can set javaScript on the textbox to remove wrong dates and show an "error" label with a message like "date/time must be X". If you can use AJAX, there are some pretty neat samples here.

updatepanel doesnt update correctly, must click twice to update

I am using an update panel and when I click a button it will update all the panels.
updapanel1.update() is very simple, but my data is not updating unless I hit the button twice.
My gridviews shows data for a selected user, and then all the grids reflect that users data.
works fine all the update panels work for the gridviews.
Now for somereason when i try to do a row count and update the panel with the summary, it does not work, i get either the previous users summary or if i hit update again for the same user i get the correct data.
'the grids are in these panels
UpdatePanel1.Update()
UpdatePanel2.Update()
UpdatePanel4.Update()
UpdatePanel6.Update()
UpdatePanel7.Update()
'the things that are not updateing correctly
rqnum.Text = GridView3.Rows.Count
oknum.Text = GridView4.Rows.Count
xlnum.Text = GridView5.Rows.Count
dynum.Text = DataList1.Items.Count
UpdatePanel8.Update()
Panel1.Visible = False
Without seeing the code for this we cannot guarantee that we are giving you the right answer, but just a thought. If the code you posted is the actual code, I would re-order things a bit.
Do the updates to the content
Then call "update" on the panels
This ensures that your content updates are actually sent to the panels. My guess is this is why it takes that second click. So something like this.
'Update content and toggle visibility of controls
rqnum.Text = GridView3.Rows.Count
oknum.Text = GridView4.Rows.Count
xlnum.Text = GridView5.Rows.Count
dynum.Text = DataList1.Items.Count
Panel1.Visible = False
'Now update all needed panels
UpdatePanel1.Update()
UpdatePanel2.Update()
UpdatePanel4.Update()
UpdatePanel6.Update()
UpdatePanel7.Update()
UpdatePanel8.Update()

WEIRDEST ERROR EVER: ASP.NET and Firefox?

I've always thought that server-side code is unaffected by the browser requesting it, but I've just come across an exception:
I have a button that when clicked, changes the button's CSS class (and those relative to it) and rebinds a GridView with new data. The function is this:
Private Sub lbViewUnUsed_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbViewUnUsed.Click
lbViewUsed.CssClass = "button small"
lbViewUnUsed.CssClass = "button small selected"
BindUsage(UsageBinding.UnUsed)
End Sub
In IE, this works perfectly. However, in Firefox, the BindUsage() function stops firing midway and nothing gets accomplished at all! In my frustration, I inserted Debug.Assert() statements after every line of code in the BindUsage() to see what was going on, and sure enough, the function would not go all the way through in Firefox ONLY.
The BindUsage() function is this (with the Debug assertions still in):
Private Sub BindUsage(ByVal bindWhat As UsageBinding)
Debug.Assert(False, 1)
If bindWhat = UsageBinding.Used Then
gvUsage.DataSource = sUser.GetWordsMarkedWithUsage(True)
gvUsage.Columns(0).Visible = False 'hide button column'
Else
Debug.Assert(False, 2)
gvUsage.DataSource = sUser.GetWordsMarkedWithUsage(False)
Debug.Assert(False, 3)
Dim userInfo As UserAccount.LoginInfo = UserAccount.GetUserLoginInfo
Debug.Assert(False, 4)
Dim showUsedButton As Boolean
Debug.Assert(False, 5)
showUsedButton = (userInfo.UserName.ToLowerInvariant = sUser.UserName.ToLowerInvariant)
Debug.Assert(False, 6)
gvUsage.Columns(0).Visible = showUsedButton 'show button column'
Debug.Assert(False, 7)
End If
Debug.Assert(False, 8)
gvUsage.DataBind()
Debug.Assert(False, 9)
End Sub
The above function does not make it past 5 in Firefox. I'm guessing there's some sort of problem with the assignment of the showUsedButton variable, but I can't figure out what it would be. Why would this fail only in Firefox, but not in any other browser especially since this is occurring on the server???
It's happening on the server, but you are retrieving data that was generated by the client:
UserAccount.GetUserLoginInfo
I would review your stored data and see what's different in it based on client application and see how it's handled.
Well, it's a bit of a guess, but...
What exactly does UserAccount.GetUserLoginInfo do? If I had to guess, it tries to do something browser-specific. For example, it could try and read a cookie from the client? If it does, then my next guess is that userInfo or either userInfo.UserName is null, thus throwing a NullReferenceException.
It could be that IE accepts cookies, and firefox does not. Hence no error in IE, but only in Firefox.
Again, this is guesswork, I'm not strong in VB.NET and have no idea what that UserAccount class is. Maybe if you'd give use the errormessage, it could mean some more.
Would you definitely spot if any exceptions were being thrown? If not, fix that before you do anything else.
As for why it might be browser-specific:
If it depends on what data is sent by the browser and how, then clearly the browser can change the behaviour
I believe ASP.NET renders in a browser-specific way; if your code is touching the rendering logic, it may be behaving differently depending on user agent.

Resources