RadControl DateTimePicker Selecting new time doesn't remove highlight from previous selection - c#

This is not browser specific - the behavior exists in Firefox and IE. The RadControl is being used within a User Control in a SiteFinity site.
Very little customization has been done to the control.
<telerik:RadDateTimePicker ID="RadDateTimePicker1" runat="server"
MinDate="2010/1/1" Width="250px">
<ClientEvents></ClientEvents>
<TimeView starttime="08:00:00" endtime="20:00:00"
interval="02:00:00"></TimeView>
<DateInput runat="server" ID="DateInput"></DateInput>
</telerik:RadDateTimePicker>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
RadDateTimePicker1.MinDate = DateTime.Now;
}
}

[Disclaimer, I work for Telerik]
I don't specifically know what the issue is, however here are some general troubleshooting steps that might help unearth the issue:
Check for Javacript errors - (Firefox's Error Console would do it)
Isolate the RadDateTimePicker control from Sitefinity - (Create a normal ASPX page and place the RadDateTimePicker control on this page. Does it work in this environment?)
Check for stylesheet issues using Firebug and/or remove stylesheets (backup first).
In general, keep simplifying until it starts working then re-add complexity until it breaks again. This normally tells me where the problem is.
Alternately, you could send your project/code to Telerik support. Best of luck.

Can you try changing MinDate to use:
RadDateTimePicker1.MinDate = System.DateTime.Parse(String.Format("{0}/{1}/{2}", System.DateTime.Now.Month, System.DateTime.Now.Day, System.DateTime.Now.Year - 1))
And tell me if the behavior changes.
Also, is the new highlight being shown as well, or is it stuck on the old highlighting completely?

Related

Response.Write not working in ASP.NET

I have a calendar named poDateCalendar, I wanted to make it so whenever the user selects the calendar to be any earlier than today's date, there will be a response as follows:
protected void poDateCalendar_SelectionChanged(object sender, EventArgs e)
{
if (poDateCalendar.SelectedDate < System.DateTime.Today)
{
Response.Write("<script>alert('Warning: you are selecting a PO date earlier than today's date')</script>");
}
poDateCalendar.Visible = false;
poDateBtn.Text = poDateCalendar.SelectedDate.ToShortDateString();
}
It worked the first time I tried it, but somehow now it doesn't work anymore, is there anything I did wrong?
I also tried doing breakpoints, it passed through the if statement and did run the response.write. However, there's just nothing that is displayed after.
Just replace your code with the following line
Response.Write("<script> alert(\"Warning: you are selecting a PO date earlier than today's date\");</script>");
In your case your code is failing because you have a single quote at "today's" which is making your code to fail. So I am using escape sequence at start and end of alert message.
Check the raw HTML sent to the browser. Likely that script was rendered before the opening html tag. There is no page or DOM yet, and so even if the browser ran the javascript at all it wouldn't know what to do with it.
This happens because of where you are in the ASP.Net Page Life Cycle at the time that code runs. A page class in ASP.Net works by first building up all of the controls and properties to have the correct data. Then, once that is all finished, there is a rendering phase where those controls are transformed into HTML for your browser. Before this rendering phase, anything you send to Response.Write() is going to a response stream that hasn't even sent headers to the browser yet.
To get around this, instead of writing to the Response stream direclty, use the Page.RegisterStartupScript() method.
I don't quite get the point - Allow users to do what they're not supposed to do, and then shout when they do so. + Message box / alerts are the old school ways of doing things. That's a bad user experience, IMHO.
I have a better suggestion here for you. You could instead disable to previous dates so that they can't select in first place. You can use DayRender event for that.
<asp:Calendar ID="poDateCalendar" runat="server" OnDayRender="poDateCalendar_DayRender" />
In code-behind:
protected void poDateCalendar_DayRender(object sender, DayRenderEventArgs e)
{
if (e.Day.Date < DateTime.Today)
{
e.Day.IsSelectable = false;
// Additionally grey out dates if you want
}
}

Intellisense indicates that form doesn't exist

I opted to copy my web code from one page different page just because it made more sense in the scheme of things to have it be the 'Default.aspx' page. I figured no biggie... copy all but the top line and make some minor alterations to the aspx page then copy all of the aspx.cs page and should be golden.
Wasn't that clean to my surprise!
First had to redefine my sql connections (not a big deal).
But the thing that really has be in a bit of a quandary is Intellisense has gone stupid on me regarding the FormView used on the page.
<asp:FormView runat="server" ID="ARS30InputFrm" DataSourceID="ARFS" DefaultMode="Insert">
This is clearly in my aspx page. Data source works all should be fine. But I have an error over on the aspx.cs where I redline on the form name on line three here and the help indicates that it doesn't exist!
protected void ARSControlNumTextBox_TextChanged(object sender, EventArgs e)
{
TextBox thecontrol = (TextBox)ARS30InputFrm.Row.FindControl("ARSControlNumTextBox");
if (thecontrol != null)
Session["CCtrl"] = thecontrol.Text;
}
ie: TextBox thecontrol = (TextBox).... ARS30InputFrm .... is where the error flags.
Any idea's on how to clear this issue? I've tried rebuilding, reloading, but nothing seems to work. This clearly is the name of the form!
Well this is not an answer to 'WHY' intelisense went wacko, but I was able to solve the issue by blowing away the aspx and aspx.cs and recreating them as I had done before (about 3 minutes of copy work) and it worked straight up!
It simply must have been something in VS that was glitchy and didn't go down right the first time through. The second time was a charm.
Live and learn...

Display/hide control in Webpart based on edit/browse mode

I have a Visual Studio project in which I have created a Visual Webpart. In the user control I have a panel which I want to display in edit mode and hide in browse mode.
ASP.NET code snippet:
<asp:panel runat="server" ID="myControl">
C# code snippet in user control code behind:
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
WebPartManager wpm = WebPartManager.GetCurrentWebPartManager(this.Page);
if (wpm.DisplayMode == WebPartManager.BrowseDisplayMode)
{
myControl.Attributes.Add("style", "display: none");
}
else if (wpm.DisplayMode == WebPartManager.EditDisplayMode)
{
myControl.Attributes.Add("style", "display: block");
}
}
This works, but if I have two same webparts on same page and put one webpart is edit mode it shows the panel in both webparts. It seems the OnPreRender event code runs for both webparts on page.
I even tried writing code as this.myControl.Attributes.Add("style", "display: block"); but it still didn't work.
I want the OnPreRender code to run only on its webpart and not modify the other webaprt on page. How can I resolve this? Is there any better (or preferred) way to do it?
NOTE: I need to use display: none because the panel would be accessed via JavaScript.
PS: This is a cross post from here as I did not get any satisfactory answers.
I do the same on the page load, and it works for me just fine .. (page has about 10 WP and only 1 behaves differently in the edit mode.)
Maybe what you mean is that you have 2 SAME webparts on the page? Then I guess both webparts will behave equally because WebPartManager.DisplayMode returns you the mode of the page, not the webpart. (see msdn).

Visual Studio 2008 can't recognize control(in webform page) in partial class

I insert a Textbox control in webform page,but I can't find it in partial class when I use it like this.txtPaySerialNumber.Text,It looks like I had not insert that in webform page.
The old control I had inserted had no problem. I have develop web form a year, this crazy thing happened only in vs2008.(My OS is Windows 8 64).
It's not exactly clear without an example of your scenario, but a couple of things to check....
Make sure you're control is defined in the page (and properly, check the error view for bad markup declarations, etc.):
<asp:TextBox runat="server" ID="PaySerialNumber />
You'll likely noticed I summarily abandoned the awful Hungarian Notation.
Then in the code-behind, access it (omitting the double this prefix (which I'm not sure whether to take literally from your post or not):
PaySerialNumber.Text = "some text";
If that fails, try it in the markup file itself:
<script runat="server" language="CSharp">
void Page_Load(object sender, EventArgs e) {
PaySerialNumber.Text = "some text";
}
</script>
If that works, then you likely have a mismatched page declaration, so it's not pointing to the right code-behind file.
If all else fails and the page, code-behind, or whatever, still isn't seeing the thing, then try a "clean solution and then "rebuild"; perhaps even restarting VS to reload the project after a clean.
If it still isn't working, then we need more information.

C# - Using Awesomium to Interact with Gmail

I'm able to navigate to gmail, but then I want to do something as simple as enter the credientials and click the login button.
private void btnSubmit_Click(object sender, EventArgs e)
{
btnSubmit.Enabled = false;
webGmail.LoadURL("http://www.gmail.com");
webGmail.LoadCompleted += ExecuteSomething;
}
private void ExecuteSomething(object sender, EventArgs eventArgs)
{
webGmail.ExecuteJavascript(#"<script src = 'http://code.jquery.com/jquery-latest.min.js' type = 'text/javascript'></script>");
webGmail.ExecuteJavascript(#"$('#Email').val('foo');");
webGmail.ExecuteJavascript(#"$('#Passwd').val('bar');");
webGmail.ExecuteJavascript(#"$('#signIn').click();");
}
Nothing happens. I know using developer tools with Chrome that you cant modify anything on the page. But is there a way of filling in forms?
Are there any other better headless browsers? I actually need one that supports a web control that I can put into my form so that I can see what is going on. This is mandatory
The problem is that the script tag is not javascript - it's HTML - so executing it as javascript will just throw an error. To load a script with the ExecuteJavascript method, you'd need to create a script element in javascript and inject it into the page head.
See here for an example:
http://www.kobashicomputing.com/injecting-jquery-into-awesomium
I recently came across a similar problem. I tried cefsharp, awesomium, open-webkit-sharp, geckofx. The most advanced was, oddly enough, WebBrowser. It allows you to perform almost all activities directly with C#. For example, click on a submit button in C# you could only in WebBrowser. If you still want to use an alternative engine, I recommend the open-webkit-sharp - it is the most advanced of them (although it has the same problem with the click of buttons).
WatiN has an Javascript implementation for Webkit, which Awesomium is based on, the source code is free and can be downloaded at their homepage. Good luck.
Maybe this question could help you too, calling Javascript from c# using awesomium.

Categories

Resources