|
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
|
|
|
|
|
Please could you elaborate on what the problem is precisely. That's alot of code to wade through without knowing the bit to focus on.
|
|
|
|
|
No one is going to look through this useless unformatted drivel. Format the code using the pre tags, i.e. "code block" and only include what is necessary, not everything.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
hi,
In my project i am using "ajaxToolkit:CalendarExtender" with Textbox.
If i am entering invalid date like 12/56/2010(mm/dd/yyyy), that time i am getting proper validation message but after getting the msg the textbox.text is getting changed into 12/31/1969 default. In the code no where i wrriten the code like this.
But when see the view source code of the page, textbox value contains invalid date.
This is strange thing that i am facing. Anybody knows the root cause of this please tell me.
The code is
<asp:textbox id="txtDate" cssclass="input10Char small" runat="server" maxlength="10">
<ajaxtoolkit:calendarextender
="" id="DateCalendarExtender" cssclass="CalendarControl" runat="server" popupposition="Right" format="MM/dd/yyyy" popupbuttonid="CalendarButton" targetcontrolid="txtDate">
Thanks in Advance for your solution.
|
|
|
|
|
Hi all,
I am facing a problem using update panel.
I have an update panel in a page with UpdateMode="Conditional"
the update panel contains a grid view.I want to fetch a particular row's value from that grid view and put it in to a label which is out side the update panel on select index change event.My code is running.I can debug it.But label's value is not changing.on the select index change method of the grid view.
|
|
|
|
|
Hi,
The label should be added inside the UpdatePanel in order to be updated.
Regards,
Jamil
|
|
|
|
|
souravghosh18 wrote: label which is out side the update panel
Here is the problem.
You have two solutions for the same.
1. Put the Label control with in the same UpdatePanel of Gridview.
2. Put Lable control into a different updatepanel ( Say updatepanel2 ), Change the UpdateMode="Conditional" . On Gridview Selected Index Change Event along with set value to lable, you need to do UpdatePanel2.Update()
Hope this will help you
|
|
|
|
|
Abhijit Jana wrote: need to do UpdatePanel2.Update()
Not necessary. Using a postback trigger is all that is needed.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Place the label in an update panel and set a postback trigger for the grid.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Hi all
I am working on property website. we want to display properties on sale in google map using asp.Net. How to do that?
Thanks for any suggestions?.............
|
|
|
|
|
|
what about code
|
|
|
|
|
Have you even opened the link? Have you even tried a cursory search? Would you like someone to write this for you?
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
ya i write a code in which when i click on property a pop window opens
anyway i got the javascript code
if u wana know then check following link
Sorry to bother u....
thanks for your help anyway.....................
|
|
|
|
|