set mintime and maxtime of timefield dynamically in ext.net - asp.net

I am working with EXT.NET 1.2
I want to set minTime and maxTime from codebehind(from cs Page).
I ha dwritten following code but not working that code.. is their any mistake or is ther any another method(through Javascript)??
Code
tmFrom.Increment = 30;
string strmin = obj.startTime.ToShortTimeString();
DateTime dtmin = DateTime.ParseExact(strmin, "H:mm tt", CultureInfo.InvariantCulture);
string strmax = obj.endTime.ToShortTimeString();
DateTime dtmax = DateTime.ParseExact(strmax, "H:mm tt", CultureInfo.InvariantCulture);
tmFrom.Format = "H:mm";
tmFrom.MinTime = dtmin.TimeOfDay;
tmFrom.MaxTime = dtmax.TimeOfDay;
I am setting minTime and maxTime from Database value.

Based on your code sample, it appears obj.startTime and obj.endTime are both already DateTime objects. You should not have to convert into Strings, then back into DateTime objects.
The following sample demonstrates the complete scenario.
Example
<%# Page Language="C#" %>
<%# Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
var startTime = DateTime.Now.AddMinutes(-215);
var endTime = DateTime.Now.AddMinutes(215);
var time = this.TimeField1;
time.Increment = 30;
time.Format = "H:mm";
time.MinTime = startTime.TimeOfDay;
time.MaxTime = endTime.TimeOfDay;
}
</script>
<!DOCTYPE html>
<html>
<head runat="server">
<title>Ext.NET Examples</title>
</head>
<body>
<ext:ResourceManager runat="server" />
<ext:TimeField ID="TimeField1" runat="server" FieldLabel="Time" />
</body>
</html>
Hope this helps

Related

ASPX + Vb.Vet simple in-browser calculation form

I am absolutely certain I'm mixing two kinds of syntax incorrectly due to trying to hack together from different samples. I am not familiar with either ASPX nor VB.Net, and am stuck at the first hurdle.
The aim is for a user to enter a string of numbers (from a lastlogontimestamp in epoch time) and return it formatted as a local date/time.
It's failing at line 4 in IIS 7 - CS1026: ) expected.
<%# Page Language="VB" %>
<script runat="server">
Sub submit(sender As Object, e As EventArgs)
long value = (long)txt1.text
DateTime pwdLastSet = (DateTime.FromFileTimeUtc(value)).ToLocalTime
lbl1.Text="Converted date: " & pwdLastSet
End Sub
</script>
<html>
<head></head>
<body>
<form runat="server">
Enter the date string:
<asp:TextBox id="txt1" runat="server" />
<asp:Button OnClick="submit" Text="Submit" runat="server" />
<p><asp:Label id="lbl1" runat="server" /></p>
</form>
</body>
</html>
Update
Thanks for the comments, everyone. I'm definitely not a programmer. I did use the C# solution suggested in the comments as an exercise, with slight corrections. However, I am slightly more familiar with VB, so I should stick with that - the accepted answer was more intuitive to me.
<script runat="server">
void submit(Object sender, EventArgs e) {
long value = Convert.ToInt64(txt1.Text);
DateTime conValue = (DateTime.FromFileTimeUtc(value)).ToLocalTime();
lbl1.Text = "Converted date: " + conValue;
}
</script>
As the Page level language is defined as C# , so the compiler will try to compile the code as C#, and hence the expected exception is appearing. So changing the Language solves the exception
<%# Page Language="VB" %>
Now the actual Vb code is also wrong. As the way variables and casting is written its not the Way happen in VB.
<script runat="server" >
Sub submit(sender As Object, e As EventArgs)
Dim value = txt1.Text
Dim pwdLastSet = (DateTime.FromFileTimeUtc(value)).ToLocalTime
lbl1.Text="Converted date: " & pwdLastSet
End Sub
</script>
So I will suggest get the hold of language which you want to proceed with C# or VB, and do the changes accordingly.
As others have pointed out you have posted a weird hybrid between VB and C#. I'm not very familiar with C# but this should be more like it.
void submit(Object sender, EventArgs e) {
long value = (long)txt1.text;
DateTime pwdLastSet = (DateTime.FromFileTimeUtc(value)).ToLocalTime();
lbl1.Text = "Converted date: " + pwdLastSet;
}

Iframe visible very short time in IE9 then disappears

I have a usercontrol which is on a webpage and that webpage is shown in a iFrame.
Form source:
<%# Page Language="vb" AutoEventWireup="false" CodeBehind="FileUploadForm.aspx.vb"
Inherits="IST.FileUploadForm" %>
<%# Register Src="myFileUpload.ascx" TagName="myFileUpload" TagPrefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:PlaceHolder ID="ph1" runat="server"></asp:PlaceHolder>
</div>
</form>
</body>
</html>
Code behind:
Imports System.IO
Public Class FileUploadForm
Inherits System.Web.UI.Page
Private WithEvents myFileUpload1 As myFileUpload
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim myUploadLocation As String
myUploadLocation = Request.QueryString("loc")
If myUploadLocation = Nothing Then
myUploadLocation = Server.MapPath("~\temp")
End If
Dim allowed As String
allowed = Request.QueryString("accepts")
If allowed = Nothing Then
allowed = ""
End If
myFileUpload1 = CType(Me.LoadControl("myFileUpload.ascx"), myFileUpload)
myFileUpload1.ID = "fuOfferte"
myFileUpload1.AllowedFiles = allowed
myFileUpload1.FileLabelText = "File"
myFileUpload1.NotAllowedText = "This file extention is not allowed."
myFileUpload1.UploadButtonText = "Upload file"
myFileUpload1.UploadLocation = myUploadLocation
ph1.Controls.Add(myFileUpload1)
End Sub
Private Sub myFileUpload1_FileUploaded(file As String) Handles myFileUpload1.FileUploaded
Session("UploadedFileName") = file
End Sub
End Class
Behind code in main page:
pnMNCfile = New Panel
pnMNCfile.ID = "pnMNCfile"
pnMNCfile.Style("position") = "absolute"
pnMNCfile.Style("left") = "45px"
pnMNCfile.Style("top") = "30px"
pnMNCfile.Style("width") = "540px"
If Request.Browser.Browser.ToLower = "ie" = False Or (Request.Browser.Browser.ToLower = "ie" = True And CInt(Request.Browser.Version.Substring(0, 1)) > 8) Then
pnMNCfile.Style("height") = "80px"
Else
pnMNCfile.Style("height") = "87px"
End If
pnMNCfile.Style("z-index") = "999"
pnMNCfile.BorderStyle = BorderStyle.None
pnMNCfile.BackColor = Drawing.Color.LightGray
pnMNCfile.BorderWidth = 1
pnMNCfile.Attributes.Add("OnMouseOut", "BalloonPopupControlBehavior.hidePopup();")
pnMNC3.Controls.Add(pnMNCfile)
Dim lit As New Literal
lit.Text = "<IFRAME id=""frMNCfileUpload"" frameborder=""0"" scrolling=""auto"" allowtransparency=""true"" runat=""server"" width=""100%"" height=""100%"" src=""FileUploadForm.aspx?loc=" + CStr(Session("userfolder")) + "&accepts=xls_xlsx_doc_docx""></IFRAME>"
pnMNCfile.Controls.Clear()
pnMNCfile.Controls.Add(lit)
The problem is that when the page loads in IE9 you see the iframe very shortly (less than 0.5 sec). In Chrome it is visible without any problem.
When I do a right mouseclick in the iframe area and do a refresh, the content is visible.
I also tried with a border around the iframe. When it is not visible, also the border is not visible. In chrome you can then see the border too.
What is happening here?
Is this a bug in IE or (more likely) am I doing something wrong?
Dirty fix would be to add a auto refresh to the webpage with the usercontrol.
any thoughts?
rg,
Eric
I had the same issue with IE9 for various reasons and works with Chrome.
1. Configure Asp.net to use a cookieless session state. This might help...
<sessionState cookieless="true" mode="InProc"></sessionState>
</system.web>
</configuration>
or
2.
or try this too:
Response.Cache.SetCacheability(HttpCacheability.NoCache);
example:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="GeneralLedgerCodeListingCustomForm.aspx.cs" Inherits="xyz.GeneralLedgerCodeListingCustomForm" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%
Response.Cache.SetCacheability(HttpCacheability.NoCache);
%>

Display Code Error

When I try to view the source code by using asp.net, I got this error.
Access to the path 'C:\Users\user\Desktop\Website1' is denied.
Anyone idea how to fix this?
The display code is as follow. I do not know how to fix this.
<%# Page Language="C#" runat="server" Debug="true" %>
<%# Import Namespace="System.IO" %>
<script language="C#" runat="server">
void Page_Load()
{
string filePath =
Server.MapPath(Request.QueryString["filename"]);
FileName.Text = Request.QueryString["filename"];
FileInfo file = new FileInfo(filePath);
if (file.Extension != ".mdb"
&& file.Extension != ".xml"
&& file.Extension != ".exe")
{
Code.Text = ReadFile(filePath);
}
else
{
Code.Text = "Sorry you can't read a file with an extension of " + file.Extension;
}
}
private string ReadFile(string filepath)
{
string fileOutput = "";
try
{
StreamReader FileReader = new StreamReader(filepath);
//The returned value is -1 if no more characters are
//currently available.
while (FileReader.Peek() > -1)
{
//ReadLine() Reads a line of characters from the
//current stream and returns the data as a string.
fileOutput += FileReader.ReadLine().Replace("<", "<").
Replace(" ", " ")
+ "<br />";
}
FileReader.Close();
}
catch (FileNotFoundException e)
{
fileOutput = e.Message;
}
return fileOutput;
}
</script>
<html>
<head>
<title>code</title>
<link rel="stylesheet" href="style1.css" type="text/css">
</head>
<body>
<h1 class="pageHeader">Source Code</h1>
<asp:label id="FileName"
CssClass="codeheader" Runat="server"/>
<asp:Panel id="pnlCode" CssClass="code"
runat="server" Width="80%">
<asp:label id="Code" Runat="server" />
</asp:Panel>
</body>
</html>
right click on your Website1, click on properties , goto security , click on edit and then add network service and see if it solves your problem.

What control to use to display main & sub tables

ASP.NET 3.5 & SQL 2008
I have this main table & a subtable. For each set of calculation, 1 record is added to the main table & several records to the subtotal.
Most of user entered data goes into the subtable & some into the main table.
Currently I have a web page set up with several textboxes to get the data from the user & the resulting calculations are displayed in a gridview.
The gridview shows all the records from the Main table.
Each time the user selects a record from the gridview, I want to invoke another page where the user can change the data for the selected record.
It will be nice if I can display the 1 record from the main tablle & all the related records form the subtable.I don't want to use free floating textboxes.
What controls will be the easiest to use for such an application?
you can use grid view in two pages it self...
Here you have to use session variables to store the value of gridview rows in first page then retrieve the session value and display the row in gridview control in the second page.
If you use gridview control to display the data which get from database in the first page ,as far as I know you can also just pass the unique value of record(such as id) to an other page ,then use the unique value as a condition to search the record in database and display the record by using gridview control in the second page.
Sample:
1.Code in the first page(.aspx):
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server"
onrowdatabound="GridView1_RowDataBound">
<Columns>
<asp:TemplateField>
<HeaderTemplate>PassValue</HeaderTemplate>
<ItemTemplate>
Pass
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>
2.Code in the first page(.cs):
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Bind();
}
}
public void Bind()
{
this.GridView1.DataSource = Get_source();
this.GridView1.DataBind();
}
// You can get the datatbale form your own database.
// I get the datasource like this in order to run the sample convenient.
public DataTable Get_source()
{
DataTable dt = new DataTable();
DataRow dr;
string XM = "true,false,false,true";
string XMM = "1,2,3,4";
string[] list1 = XM.Split(',');
string[] list2 = XMM.Split(',');
dt.Columns.Add(new DataColumn("ActiveStatus"));
dt.Columns.Add(new DataColumn("number"));
for (int i = 0; i < list1.Length; i++)
{
dr = dt.NewRow();
dr["ActiveStatus"] = list1[i];
dr["number"] = list2[i];
dt.Rows.Add(dr);
}
return dt;
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
int i = e.Row.RowIndex;
Session["row"+i] = e.Row;
}
3.Code in the second page(which named as OtherPage.aspx)
OtherPage.aspx:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
</div>
</form>
</body>
</html>
4.Code in the second page(.cs):
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["id"] != null)
{
string i = Request.QueryString["id"].ToString();
if (Session["row"+i] != null)
{
DataTable dt = new DataTable();
DataRow dr = dt.NewRow();
GridViewRow row = (GridViewRow)Session["row" + i];
for (int xm = 0; xm < row.Cells.Count; xm++)
{
dt.Columns.Add(new DataColumn());
dr[xm] = row.Cells[xm].Text;
}
dt.Rows.Add(dr);
this.GridView1.DataSource = dt;
this.GridView1.DataBind();
}
}
}
if you want to modify the data in second page, you can modify ... I hope it will helps you...

How do I stop a databound dropdown list from htmlencoding?

ddlCats.DataSource = listOfCats;
ddlCats.DataBind();
If an item contains say, &, it will appear in the ddl as &
How can I stop this? I am using asp.net
im having the same problem here and here is the code for those interested (not a fix but a example of the problem )
<%# Page Language="C#" AutoEventWireup="true" CodeFile="HtmlEncodeDropDownList.aspx.cs" Inherits="ForumExampleCode_HtmlEncodeDropDownList" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>HTML Encode Drop Down List Example (english, c# only)</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h1>HTML Encode Drop Down List Example (english, c# only)</h1>
<asp:dropdownlist id="ddlCountry" runat="server" />
<div>
This is how it should look in the drop down list:<br />
côte d'ivoire<br />
são tomé and príncipe
</div>
</div>
</form>
</body>
</html>
and code behind is here
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class ForumExampleCode_HtmlEncodeDropDownList : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
#region region 1: create a datatable and fill with values
//note: declare objects
DataTable countryTable = new DataTable();
//note: add data columns to datatabl
DataColumn newColumn1 = new DataColumn();
newColumn1.AllowDBNull = false;
newColumn1.Caption = "three letter ISO country abbreviation";
newColumn1.ColumnName = "iso";
newColumn1.DataType = System.Type.GetType("System.String");
countryTable.Columns.Add(newColumn1);
//note: add data columns to datatable
DataColumn newColumn2 = new DataColumn();
newColumn2.AllowDBNull = false;
newColumn2.Caption = "country name";
newColumn2.ColumnName = "countryName";
newColumn2.DataType = System.Type.GetType("System.String");
countryTable.Columns.Add(newColumn2);
//note: rename table
countryTable.TableName = "CountryList";
//note: add row
DataRow newRow1 = countryTable.NewRow();
newRow1["iso"] = "abc";
newRow1["countryName"] = "côte d'ivoire";
countryTable.Rows.Add(newRow1);
//note: add row
DataRow newRow2 = countryTable.NewRow();
newRow2 = countryTable.NewRow();
newRow2["iso"] = "xyz";
newRow2["countryName"] = "são tomé and príncipe";
countryTable.Rows.Add(newRow2);
#endregion
#region region 2: bind datatable to drop down box
ddlCountry.DataSource = countryTable;
ddlCountry.DataTextField = "countryName";
ddlCountry.DataValueField = "iso";
ddlCountry.DataBind();
#endregion
}
}

Resources