|
Do not use URGENT, it is rude. We are here voluntarily to answer questions and what is urgent to you is not to anyone else.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
|
hi,
This is regarding textbox control, while seeing the page it is showing one value eg: 12/31/1969 but in the view source code of that page shows 12/58/2010.
How can it possible.
|
|
|
|
|
Well, are you looking at the same text control? Are there any other text controls in the page?
The data may be have manipulated by JavaScript code. Is there any JavaScript code that runs on page load?
|
|
|
|
|
Copy "12/31/1969" From your web page. Open the View Soruce, Search >"12/31/1969". Check the result.
|
|
|
|
|
maybe you are updating the value using a client side code (javascript).
Regards,
Jamil
|
|
|
|
|
Hi,
I try to manage the absence of students in the exams, try to insert the id of students absent for each matter,to facilitate that to the user i want insert id_student at once (not one after one by textbox simple)is ther any control or method to do that?
Thanks
|
|
|
|
|
Yes, you can take listbox which shows you student id and name (combination, however in background it will give you ids)
so you can select multiple items from listbox.
On each matter, there is two checkbox (absent and present)
so just select multiple student from listbox
and mark absent or present checkbox and insert it
into database.
Hope this will help!
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|
Hi!
I do not know if will be easy for the user ,because it is hundreds of students by by matter ,so i must show them all for and check those abcent.
Thanks .
|
|
|
|
|
Hi!
How we can paginate a listbox?
Thanks
|
|
|
|
|
You do not required to do pagination in listbox,
it will automatically shows you scroll bar...
The other best option it you do not want to use
listbox is create your custom control.
Because if you are using grid control then it will
not remember your selection when you select
options from multiple pages....
Hope this will help!
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|
Thanks Jinal Desai - LIVE,
creating user control seems complicated,I think using multiline textbox:
the user will simply enter ID of abcent students line and in the end I enter that id in the database by a clic buton ,Waht do you Think?
Thank you.
|
|
|
|
|
ya that will be also nice idea.
If you want to just take IDs then it is fine...
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|
Hi,
That's what I wanted ,it easier for the user but I did not know if there multiline textbox.
I do not know how to check if those id are correct,to prevent the user from making mistakes and insert an id which does not exist in the table student.
Thanks
|
|
|
|
|
Of course there exists multiline textbox in asp.net
You need to use normal textbox and just make it
multiline textbox.
You need to give rows, columns and textmode property according to your
requirement.
Try following....
<asp:TextBox ID="TextBox1" runat="server" Columns="50" Rows="5" TextMode="MultiLine"></asp:TextBox>
Hope this will help!
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|
I want to create a class to persist some data which will be accessible no matter what page I navigate to. I am using Server.Transfer(path, true) to switch between pages, and my first thought was to use a static class. But a static class can only contain static members and I need to instantiate new objects on different pages that need to be accessible from subsequent pages. What is the best way to persist this data in a class? Language is C#, .Net framework 3.5.
|
|
|
|
|
It is very simple.
Just create any class in your web application in .cs file or refer any dll (contains your class)
create instance of it.
Store the object in session or application and you can access it from any of your
subsequent .aspx pages.
Hope this will help!
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|
Naptown Brown wrote: But a static class can only contain static members and I need to instantiate new objects on different pages that need to be accessible from subsequent pages.
you can use static class by using
classname.methodname
for this you have to inherit class at the top of the page.aspx.cs
using namespacename.classname;
hope this may help u.............
|
|
|
|
|
Create a class that inherits "System.UI.Web.Page" and put the properties there that you need to be able to access from all pages. Be sure to build your accessors there as well.
All other pages in your web application should inherit from that class. Then the properties you built there will be accessible...
Something like this:
Public class myPage : Page
{
protected SqlConnection conn;
protected SqlCommand cmd;
public myPage() : base()
{
string connectionString = ConfigurationManager.ConnectionString["DBConnectionString"].ConnectionString;
this.conn = new SqlConnection(connectionString);
this.cmd = new SqlCommand();
this.cmd.Connection = conn;
}
protected int myIntProperty
{
get { return CodeLayer.myProperties.myInt; }
set { CodeLayer.myProperties.myInt = value; }
}
}
Now when you create a new page in your web application, your page should inherit this class. In this example that would mean that whenever the page loads, you would already have an SqlConnection and SqlCommand object defined and usable and you can access your "myInt" property.
public partial class PageOne : myPage
{
protected void Page_Load(object sender, EventArgs e)
{
cmd.CommandText = "SELECT * FROM myTable";
this.myIntProperty = 10;
}
}
- Dave
|
|
|
|
|
Thanks so much for the great example, Dave. I did not consider something like this. It looks like a very workable solution for calling static methods, but my real goal is to persist data in objects between calls to different pages and to do that I cannot use static classes since I have to instantiate data.
I thought about it alot and I think the best approach is to serialize the data in an XML data island between page calls. Then I can pick it up on the next page, de-serialize it, and move on.
Thanks again.
Adam
|
|
|
|
|
You are correct, the data must be stored somewhere. I generally use a database, but any storage method would work.
The idea in my example would be that CodeLayer.myProperties.myInt; would actually do the XML de-serialization in the property's get accessor. It just makes accessing those values very simple when you get to the page level...
- Dave
|
|
|
|
|
Why are you using Server.Transfer? Do you really need all of the viewstate and posted data from one page to be sent to the other? That can be pretty inefficient.
Create a class file in your web project. I would probably put it in its own namespace and then for each page that needs to use the class, add a using statement for that namespace.
What other objects do you need to instantiate and where do those classes live? What kind of persistence are you thinking of? Persisting in memory is usually not a good idea as that doesn't scale very well. You might want to do some research on some design patterns like the domain object model. Then you can look for an ORM (Object relational mapper) that will help you get your objects into and out of a database.
|
|
|
|
|
I put a class file in my project and put it in its own namespace and it is accessible to every page, but I really need access to the data in objects that I instantiate. The data I need must persist for the life of the applicaiton. It is kind of like a wizard app where I am accumulating data page to page for final submission at the end. This is only a 3 month project so I want to keep it simple since the timelines are a bit tight.
I thought about it alot and I think the best approach is to serialize the data in an XML data island between page transfers. Then I can pick it up on the next page, de-serialize it, and move on.
Thanks for your help.
Adam
|
|
|
|
|
namespace Ashwin {
public class Global : System.Web.HttpApplication, ICacheManager {
protected void Application_Start(object sender, EventArgs e) {
//Load the cache for the first time.
ReloadCache("All");
}
protected void Application_End(object sender, EventArgs e) {
//Cleanup anything that we left if we left anything using the SubmitReport.asmx
/*string tempPath = Server.MapPath("TempData");
if (System.IO.Directory.Exists(tempPath))
System.IO.Directory.Delete(tempPath, true);*/
}
/// <summary>
/// When the session starts.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Session_Start(object sender, EventArgs e) {
UserSession session = new UserSession(Request);
try {
LoggedInUserInfo liui = session.Login();
// if user successfully logged in
// then store in Session cache
if(liui != null) {
CacheManager.SetCache("loggedInUser", CacheManager.cacheTypeEnum.Session, liui, this);
// get the top 10 Read reports in last 30 days i.e. one month
Report report = new Report();
IList list = report.GetTopReadReport(10, DateRangeEnum.OneMonth, ReportClassificationEnum.All, liui.User.UserId);
CacheManager.SetCache("TopReadReport", CacheManager.cacheTypeEnum.Session, list, this);
FillCache("SavedSearches");
}
} catch(Exception exc) {
Exception LastException = exc;
Session["LastException"] = LastException;
ErrorDetail ed = new ErrorDetail();
RecordError recordError = new RecordError();
recordError.Credentials = new System.Net.NetworkCredential(Util.GetConfigValue("WebServicesLogin"), Util.GetConfigValue("WebServicesPwd"));
recordError.PreAuthenticate = true;
ed.applicationName = "Ashwin20";
ed.browserVersion = Request.ServerVariables["HTTP_USER_AGENT"];
ed.errorUrl = Request.Url.ToString();
ed.note = LastException.Message;
ed.stackTrace = LastException.StackTrace;
ed.userName = Util.GetSimpleUsername(User);
//recordError.ReportError(ed);
Response.Redirect("ErrorPage.aspx");
}
}
/// <summary>
/// Fill in the cached value and return the list.
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
private IList FillCache(string key) {
CacheManager.cacheTypeEnum application = CacheManager.cacheTypeEnum.Application;
CacheManager.cacheTypeEnum session = CacheManager.cacheTypeEnum.Session;
Org org = new Org();
SpecificSubject specificSubject = new SpecificSubject();
BusinessUnit busisnessUnit = new BusinessUnit();
OptinTitle optinTitle = new OptinTitle();
GeoArea geoArea = new GeoArea();
Function funtion = new Function();
Cop cop = new Cop();
Prod prod = new Prod();
DateRange dateRange = new DateRange();
SecurityGroup securityGroup = new SecurityGroup();
SecurityGroupInfo sgi = new SecurityGroupInfo();
Report report = new Report();
IList list = null;
// These tables hardly changes so we are going to store them
// in the application cache using the CacheManager.
if (key == "All" || key == "SecurityGroup") {
list = securityGroup.GetSecurityGroup();
CacheManager.SetCache("SecurityGroup", application, list, this);
}
if (key == "All" || key == "Organizations") {
list = org.GetOrg();
CacheManager.SetCache("Organizations", application, list, this);
}
if (key == "All" || key == "KeyCompetencies") {
list = specificSubject.GetSpecificSubject();
CacheManager.SetCache("KeyCompetencies", application, list, this);
}
if (key == "All" || key == "BusinessUnits") {
list = busisnessUnit.GetBusUnit();
CacheManager.SetCache("BusinessUnits", application, list, this);
}
if (key == "All" || key == "Levels") {
list = optinTitle.GetOptinTitle();
CacheManager.SetCache("Levels", application, list, this);
}
if (key == "All" || key == "Regions") {
list = geoArea.GetGeoArea();
CacheManager.SetCache("Regions", application, list, this);
}
if (key == "All" || key == "Functions") {
list = funtion.GetFunc();
CacheManager.SetCache("Functions", application, list, this);
}
if (key == "All" || key == "CoPs") {
list = cop.GetCop();
CacheManager.SetCache("CoPs", application, list, this);
}
if (key == "All" || key == "Sectors") {
list = prod.GetSector();
CacheManager.SetCache("Sectors", application, list, this);
}
if (key == "All" || key == "DateRange") {
list = dateRange.GetDateRange();
CacheManager.SetCache("DateRange", application, list, this);
}
// Cache Top 10 Readers and Top 10 Authors
// get the top 10 Readers in last 3 months
if(key == "All" || key == "TopReader") {
list = report.GetTopReaders(10, DateRangeEnum.ThreeMonths,"");
CacheManager.SetCache("TopReader",
CacheManager.cacheTypeEnum.Application, list, this);
}
// get the top 10 Authors in last 12 months i.e. one year
if(key == "All" || key == "TopAuthor") {
list = report.GetTopAuthors(10, DateRangeEnum.OneYear, "");
CacheManager.SetCache("TopAuthor",
CacheManager.cacheTypeEnum.Application, list, this);
}
// Get submitted report count in last 30 days from the database
if(key == "All" || key == "SubmittedReportCount") {
int submittedReportCount = 0;
Report ri = new Report();
// Call DB Method
// to get total reports submitted in last 30 days
submittedReportCount = ri.GetReportsSubmittedCount();
CacheManager.SetCache("SubmittedReportCount",
CacheManager.cacheTypeEnum.Application, submittedReportCount, this);
}
// Get report count in last 30 days from the content monitor service
if(key == "All" || key == "ViewedReportCount") {
int viewedReportCount = 0;
// Call Content Monitor WebService
// to get total viewed report count in last 30 days
MonitorReportService.ReportService reportService
= new MonitorReportService.ReportService();
reportService.Credentials = new NetworkCredential(Util.GetConfigValue("WebServiceUser"), Util.GetConfigValue("WebServicePswd"));
reportService.PreAuthenticate = true;
viewedReportCount = reportService.GetApplicationAccessCount
(Util.GetConfigValue("ApplicationName"), 30);
CacheManager.SetCache("ViewedReportCount",
CacheManager.cacheTypeEnum.Application, viewedReportCount, this);
}
if (key == "SavedSearches") {
// list of the user’s Saved searches using new Isubscribe webservice
//Get the saved Searches for the current user
iSubscribeService.iSubscribeWebService isubscribeService = new iSubscribeService.iSubscribeWebService();
isubscribeService.Credentials = new NetworkCredential(Util.GetConfigValue("WebServiceUser"), Util.GetConfigValue("WebServicePswd"));
isubscribeService.PreAuthenticate = true;
LoggedInUserInfo liui = Session["loggedInUser"] as LoggedInUserInfo;
list = isubscribeService.GetAllSavedSearchesByApplication
(liui.User.UserId,
int.Parse(Util.GetConfigValue("ApplicationId")));
CacheManager.SetCache("SavedSearches", session, list, this);
}
return list;
}
#region ICacheManager Methods
/// <summary>
/// Reload the cache.
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public object ReloadCache(string key) {
object obj = null;
obj = FillCache(key);
return obj;
}
#endregion
}
}
---- Cache Manager ----
namespace Ashwin.BLL.Controls {
/// <summary>
/// Summary description for CacheManager.
/// </summary>
public class CacheManager {
//Hash table to hold all values
private static readonly Hashtable theCache = Hashtable.Synchronized(new Hashtable());
private static readonly CacheManager m_manager = new CacheManager();
/// <summary>
/// The types of cache we will deal with
/// </summary>
public enum cacheTypeEnum { Application, Session };
/// <summary>
/// Returns the singleton instance of the cache manager
/// </summary>
public static CacheManager Manager {
get { return m_manager; }
}
/// <summary>
/// Returns the cached value for the given key.
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public static object GetCache(string key) {
object ret;
CacheInfo cacheInfo = new CacheInfo();
cacheInfo.Key = key;
//Look in Application cache
ret = HttpContext.Current.Application[key];
if (ret == null) { //Look in Session
ret = HttpContext.Current.Session[key];
if (ret != null) {
cacheInfo.Type = cacheTypeEnum.Session;
cacheInfo.Value = ret;
}
} else {//Application
cacheInfo.Type = cacheTypeEnum.Application;
cacheInfo.Value = ret;
}
return ret;
}
/// <summary>
/// Adds the value to the cache
/// </summary>
/// <param name="key"></param>
/// <param name="type"></param>
/// <param name="theValue"></param>
/// <param name="container"></param>
public static void SetCache(string key, cacheTypeEnum type, object theValue, ICacheManager container) {
switch (type) {
case cacheTypeEnum.Application:
HttpContext.Current.Application[key] = theValue; //Add the value to the Application cache
break;
case cacheTypeEnum.Session: //Add the value to the Session cache
HttpContext.Current.Session[key] = theValue;
break;
}
//Add this to our hashtable
CacheInfo cacheInfo = new CacheInfo();
cacheInfo.Key = key;
cacheInfo.Type = type;
cacheInfo.Value = theValue;
cacheInfo.Container = container;
theCache[key] = cacheInfo;
}
/// <summary>
/// Returns an IList of CacheInfo objects representing all cached items
/// </summary>
/// <returns></returns>
public static IList GetAllCache() {
ArrayList list = new ArrayList();
foreach (string key in theCache.Keys) {
CacheInfo cacheInfo = theCache[key] as CacheInfo;
list.Add(cacheInfo);
}
return list;
}
/// <summary>
/// Clear the Cached Item
/// </summary>
/// <param name="key">The key to clear</param>
public static void ClearCacheReload(string key) {
CacheInfo cacheInfo = theCache[key] as CacheInfo;
if (cacheInfo != null) {
switch (cacheInfo.Type) {
case cacheTypeEnum.Application:
HttpContext.Current.Application[key] = null; //Add the value to the Application cache
cacheInfo.Value = cacheInfo.Container.ReloadCache(key);
break;
case cacheTypeEnum.Session: //Add the value to the Session cache
HttpContext.Current.Session[key] = null;
cacheInfo.Value = null;
break;
}
theCache[key] = cacheInfo;
}
}
/// <summary>
/// Clear All Items in the cache
/// </summary>
public static void ClearCache() {
foreach (string key in theCache.Keys) {
CacheInfo cacheInfo = theCache[key] as CacheInfo;
if (cacheInfo != null) {
switch (cacheInfo.Type) {
case cacheTypeEnum.Application:
HttpContext.Current.Application[key] = null; //Add the value to the Application cache
break;
case cacheTypeEnum.Session: //Add the value to the Session cache
HttpContext.Current.Session[key] = null;
break;
}
cacheInfo.Value = null;
theCache[key] = cacheInfo;
}
}
}
}
}
Please help
|
|
|
|
|
Please write your code within code block & describe more
|
|
|
|
|