| Home | Forums | Reviews | Articles | Register |
![]() |
| Thread Tools | Rate Thread |
|
|
|
| |
|
Karl Seguin
Guest
Posts: n/a
|
I believe the problem is that you need to put your code in the page_load
event. ASP.Net, unlike classic ASP, is event driven. That is, there's an page_load event which fires when the page first loads. Try: <script Language="c#" runat="server"> void page_load(){ ReportConstants reportConstants = (ReportConstants)Session["ReportConstants"]; } </script> not really sure what the goal of: > <% ReportConstants reportConstants = new ReportConstants(); %> is, since you are later overwriting it with the session variable...why create a new instance only to have it overwritten? but if you do need, it too should likely be placed in page_load. Karl -- MY ASP.Net tutorials http://www.openmymind.net/ - New and Improved (yes, the popup is annoying) http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to come!) "Stephen H." <(E-Mail Removed)> wrote in message news:CBF1B33D-86E2-4CB1-8D80-(E-Mail Removed)... > Hi, > > I have an existing web application with java beans that I wanne migrate to > ASP.NET using C#. > > The existing web application has some jsp files that use java beans as > follows: > > ... > <%@ page language="java" import="reportgen.*"%> > <%@ page import="java.lang.reflect.Array" %> > <jsp:useBean id="webAppConstants" scope="session" > class="reportgen.WebAppConstants"> > </jsp:useBean> > <% webAppConstants.loadProperties(config); %> > <% session.setAttribute("WebAppConstants", webAppConstants);%> > > <html> > <head> > <title></title> > ... > ... > <td bordercolor="#000000" valign="top"> > <table width="100%" border="0" cellspacing="0" cellpadding="0" > height="340" > class="Text_Small"> > <tr> > <td valign="top" height="72"> > <%out.print(webAppConstants.WELCOME);%> > <br> > > > Now I'm looking for a possibility to use/make some C# objects that behave > nearly the same way that java beans do. That means I want to use them in > the > html-code of an aspx-file. > > In the above example webAppConstants is a selfdefined java class. But > because of "<jsp:useBean..." the class is instantiated to webAppConstants > and > can be used in the following html-code. > > I tried the following solution that should give me an object from a > session: > > <%@ Page CodeBehind="Login.aspx.cs" Language="c#" AutoEventWireup="false" > Inherits="ReportGenerator.Login" %> > <%@ Import namespace="ReportGenerator" %> > <% ReportConstants reportConstants = new ReportConstants(); %> > <script Language="c#" runat="server"> > ReportConstants reportConstants = > (ReportConstants)Session["ReportConstants"]; > </script> > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Tran0sitional//EN" > > <HTML> > ... > > But Session is unknown. So how do I get access to the session? Or is what > would be another solution. > > Thanks in advance for any help. > > Stephen |
|
||
|
||||
|
Kevin Spencer
Guest
Posts: n/a
|
This is kind of hard to say, but you're putting the cart before the horse
here. What I mean is that, rather than trying to make ASP.Net behave like Java Beans, or ASP, which is the closest thing in the Microsoft family to Java Beans. You need to be thinking more about how to accomplish WHAT you accomplish in Java Beans with ASP.net, not HOW. That is, any programming technology exists for basically the same purpose: To satisfy requirements, or to "make something happen." Session State, for example, exists for the purpose of maintaining state acrosss a single user Session in a stateless HTTP environment. And indeed, ASP.Net has Session State, and it serves the same purpose. But you're talking about nailing nails with a hammer gun instead of a hammer, and you want to know where to hit the nail with the hammer gun. The end is the same; the means is entirely different. In other words, you need to either bite the proverbial bullet, and learn how to work with the ASP.Net object model, or stick with what you know. If you hit nails with a hammer gun, eventually, the gun breaks. On the other hand, if you use a hammer gun as it was designed, you can drive a lot more nails in a lot less time. -- HTH, Kevin Spencer Microsoft MVP ..Net Developer Ambiguity has a certain quality to it. "Stephen H." <(E-Mail Removed)> wrote in message news:CBF1B33D-86E2-4CB1-8D80-(E-Mail Removed)... > Hi, > > I have an existing web application with java beans that I wanne migrate to > ASP.NET using C#. > > The existing web application has some jsp files that use java beans as > follows: > > ... > <%@ page language="java" import="reportgen.*"%> > <%@ page import="java.lang.reflect.Array" %> > <jsp:useBean id="webAppConstants" scope="session" > class="reportgen.WebAppConstants"> > </jsp:useBean> > <% webAppConstants.loadProperties(config); %> > <% session.setAttribute("WebAppConstants", webAppConstants);%> > > <html> > <head> > <title></title> > ... > ... > <td bordercolor="#000000" valign="top"> > <table width="100%" border="0" cellspacing="0" cellpadding="0" > height="340" > class="Text_Small"> > <tr> > <td valign="top" height="72"> > <%out.print(webAppConstants.WELCOME);%> > <br> > > > Now I'm looking for a possibility to use/make some C# objects that behave > nearly the same way that java beans do. That means I want to use them in > the > html-code of an aspx-file. > > In the above example webAppConstants is a selfdefined java class. But > because of "<jsp:useBean..." the class is instantiated to webAppConstants > and > can be used in the following html-code. > > I tried the following solution that should give me an object from a > session: > > <%@ Page CodeBehind="Login.aspx.cs" Language="c#" AutoEventWireup="false" > Inherits="ReportGenerator.Login" %> > <%@ Import namespace="ReportGenerator" %> > <% ReportConstants reportConstants = new ReportConstants(); %> > <script Language="c#" runat="server"> > ReportConstants reportConstants = > (ReportConstants)Session["ReportConstants"]; > </script> > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Tran0sitional//EN" > > <HTML> > ... > > But Session is unknown. So how do I get access to the session? Or is what > would be another solution. > > Thanks in advance for any help. > > Stephen |
|
||
|
||||
|
=?Utf-8?B?U3RlcGhlbiBILg==?=
Guest
Posts: n/a
|
Hi Karl,
I already tried this. The problem with this approach is that reportConstants is only accessible in the scope of page_load. Even if I put the declaration of reportConstants before the scope of page_load I get the runtime error message "System.NullReferenceException: Object reference not set to an instance of an object." I figured out another solution for the static parts because now I know how to access html tags from the codebehind file. But there's still one remaining problem: How do I access parts in JavaScript. The following line is an example how it worked with Java: .... document.getElementById("database").value="<% out.print(reportConstants.DBNAME); %>"; .... Bernd "Karl Seguin" wrote: > I believe the problem is that you need to put your code in the page_load > event. ASP.Net, unlike classic ASP, is event driven. That is, there's an > page_load event which fires when the page first loads. > > Try: > > <script Language="c#" runat="server"> > void page_load(){ > ReportConstants reportConstants = > (ReportConstants)Session["ReportConstants"]; > > } > </script> > > > not really sure what the goal of: > <% ReportConstants reportConstants = new > ReportConstants(); %> is, since you are later overwriting it with the > session variable...why create a new instance only to have it overwritten? > but if you do need, it too should likely be placed in page_load. > > Karl > > -- > MY ASP.Net tutorials > http://www.openmymind.net/ - New and Improved (yes, the popup is > annoying) > http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to > come!) > "Stephen H." <(E-Mail Removed)> wrote in message > news:CBF1B33D-86E2-4CB1-8D80-(E-Mail Removed)... > > Hi, > > > > I have an existing web application with java beans that I wanne migrate to > > ASP.NET using C#. > > > > The existing web application has some jsp files that use java beans as > > follows: > > > > ... > > <%@ page language="java" import="reportgen.*"%> > > <%@ page import="java.lang.reflect.Array" %> > > <jsp:useBean id="webAppConstants" scope="session" > > class="reportgen.WebAppConstants"> > > </jsp:useBean> > > <% webAppConstants.loadProperties(config); %> > > <% session.setAttribute("WebAppConstants", webAppConstants);%> > > > > <html> > > <head> > > <title></title> > > ... > > ... > > <td bordercolor="#000000" valign="top"> > > <table width="100%" border="0" cellspacing="0" cellpadding="0" > > height="340" > > class="Text_Small"> > > <tr> > > <td valign="top" height="72"> > > <%out.print(webAppConstants.WELCOME);%> > > <br> > > > > > > Now I'm looking for a possibility to use/make some C# objects that behave > > nearly the same way that java beans do. That means I want to use them in > > the > > html-code of an aspx-file. > > > > In the above example webAppConstants is a selfdefined java class. But > > because of "<jsp:useBean..." the class is instantiated to webAppConstants > > and > > can be used in the following html-code. > > > > I tried the following solution that should give me an object from a > > session: > > > > <%@ Page CodeBehind="Login.aspx.cs" Language="c#" AutoEventWireup="false" > > Inherits="ReportGenerator.Login" %> > > <%@ Import namespace="ReportGenerator" %> > > <% ReportConstants reportConstants = new ReportConstants(); %> > > <script Language="c#" runat="server"> > > ReportConstants reportConstants = > > (ReportConstants)Session["ReportConstants"]; > > </script> > > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Tran0sitional//EN" > > > <HTML> > > ... > > > > But Session is unknown. So how do I get access to the session? Or is what > > would be another solution. > > > > Thanks in advance for any help. > > > > Stephen > > > |
|
||
|
||||
|
=?Utf-8?B?U3RlcGhlbiBILg==?=
Guest
Posts: n/a
|
Hi Kevin,
yes I have to learn more about ASP.Net. But metaphoric answers from people who seem to come straight out of a DIY store are not really helpfull for anybody. Bernd "Kevin Spencer" wrote: > This is kind of hard to say, but you're putting the cart before the horse > here. What I mean is that, rather than trying to make ASP.Net behave like > Java Beans, or ASP, which is the closest thing in the Microsoft family to > Java Beans. You need to be thinking more about how to accomplish WHAT you > accomplish in Java Beans with ASP.net, not HOW. That is, any programming > technology exists for basically the same purpose: To satisfy requirements, > or to "make something happen." Session State, for example, exists for the > purpose of maintaining state acrosss a single user Session in a stateless > HTTP environment. And indeed, ASP.Net has Session State, and it serves the > same purpose. But you're talking about nailing nails with a hammer gun > instead of a hammer, and you want to know where to hit the nail with the > hammer gun. The end is the same; the means is entirely different. In other > words, you need to either bite the proverbial bullet, and learn how to work > with the ASP.Net object model, or stick with what you know. If you hit nails > with a hammer gun, eventually, the gun breaks. On the other hand, if you use > a hammer gun as it was designed, you can drive a lot more nails in a lot > less time. > > -- > HTH, > > Kevin Spencer > Microsoft MVP > ..Net Developer > Ambiguity has a certain quality to it. > > "Stephen H." <(E-Mail Removed)> wrote in message > news:CBF1B33D-86E2-4CB1-8D80-(E-Mail Removed)... > > Hi, > > > > I have an existing web application with java beans that I wanne migrate to > > ASP.NET using C#. > > > > The existing web application has some jsp files that use java beans as > > follows: > > > > ... > > <%@ page language="java" import="reportgen.*"%> > > <%@ page import="java.lang.reflect.Array" %> > > <jsp:useBean id="webAppConstants" scope="session" > > class="reportgen.WebAppConstants"> > > </jsp:useBean> > > <% webAppConstants.loadProperties(config); %> > > <% session.setAttribute("WebAppConstants", webAppConstants);%> > > > > <html> > > <head> > > <title></title> > > ... > > ... > > <td bordercolor="#000000" valign="top"> > > <table width="100%" border="0" cellspacing="0" cellpadding="0" > > height="340" > > class="Text_Small"> > > <tr> > > <td valign="top" height="72"> > > <%out.print(webAppConstants.WELCOME);%> > > <br> > > > > > > Now I'm looking for a possibility to use/make some C# objects that behave > > nearly the same way that java beans do. That means I want to use them in > > the > > html-code of an aspx-file. > > > > In the above example webAppConstants is a selfdefined java class. But > > because of "<jsp:useBean..." the class is instantiated to webAppConstants > > and > > can be used in the following html-code. > > > > I tried the following solution that should give me an object from a > > session: > > > > <%@ Page CodeBehind="Login.aspx.cs" Language="c#" AutoEventWireup="false" > > Inherits="ReportGenerator.Login" %> > > <%@ Import namespace="ReportGenerator" %> > > <% ReportConstants reportConstants = new ReportConstants(); %> > > <script Language="c#" runat="server"> > > ReportConstants reportConstants = > > (ReportConstants)Session["ReportConstants"]; > > </script> > > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Tran0sitional//EN" > > > <HTML> > > ... > > > > But Session is unknown. So how do I get access to the session? Or is what > > would be another solution. > > > > Thanks in advance for any help. > > > > Stephen > > > |
|
||
|
||||
|
Karl Seguin
Guest
Posts: n/a
|
As is often the case, I have to agree with what Kevin also posted.
one question is why does this need to be done in javascript? what is "database" ? a textbox? then you should do it like: <asp:textbox id="database" runat="server" /> and in your codebehind use: database.Text = reportContants.DBNAME; Karl -- MY ASP.Net tutorials http://www.openmymind.net/ - New and Improved (yes, the popup is annoying) http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to come!) "Stephen H." <(E-Mail Removed)> wrote in message news:E307E819-7975-48BA-B3D8-(E-Mail Removed)... > Hi Karl, > > I already tried this. The problem with this approach is that > reportConstants > is only accessible in the scope of page_load. Even if I put the > declaration > of reportConstants before the scope of page_load I get the runtime error > message "System.NullReferenceException: Object reference not set to an > instance of an object." > > I figured out another solution for the static parts because now I know how > to access html tags from the codebehind file. > > But there's still one remaining problem: How do I access parts in > JavaScript. The following line is an example how it worked with Java: > ... > document.getElementById("database").value="<% > out.print(reportConstants.DBNAME); %>"; > ... > > Bernd > > > > "Karl Seguin" wrote: > >> I believe the problem is that you need to put your code in the page_load >> event. ASP.Net, unlike classic ASP, is event driven. That is, there's >> an >> page_load event which fires when the page first loads. >> >> Try: >> >> <script Language="c#" runat="server"> >> void page_load(){ >> ReportConstants reportConstants = >> (ReportConstants)Session["ReportConstants"]; >> >> } >> </script> >> >> >> not really sure what the goal of: > <% ReportConstants reportConstants = >> new >> ReportConstants(); %> is, since you are later overwriting it with the >> session variable...why create a new instance only to have it overwritten? >> but if you do need, it too should likely be placed in page_load. >> >> Karl >> >> -- >> MY ASP.Net tutorials >> http://www.openmymind.net/ - New and Improved (yes, the popup is >> annoying) >> http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to >> come!) >> "Stephen H." <(E-Mail Removed)> wrote in message >> news:CBF1B33D-86E2-4CB1-8D80-(E-Mail Removed)... >> > Hi, >> > >> > I have an existing web application with java beans that I wanne migrate >> > to >> > ASP.NET using C#. >> > >> > The existing web application has some jsp files that use java beans as >> > follows: >> > >> > ... >> > <%@ page language="java" import="reportgen.*"%> >> > <%@ page import="java.lang.reflect.Array" %> >> > <jsp:useBean id="webAppConstants" scope="session" >> > class="reportgen.WebAppConstants"> >> > </jsp:useBean> >> > <% webAppConstants.loadProperties(config); %> >> > <% session.setAttribute("WebAppConstants", webAppConstants);%> >> > >> > <html> >> > <head> >> > <title></title> >> > ... >> > ... >> > <td bordercolor="#000000" valign="top"> >> > <table width="100%" border="0" cellspacing="0" cellpadding="0" >> > height="340" >> > class="Text_Small"> >> > <tr> >> > <td valign="top" height="72"> >> > <%out.print(webAppConstants.WELCOME);%> >> > <br> >> > >> > >> > Now I'm looking for a possibility to use/make some C# objects that >> > behave >> > nearly the same way that java beans do. That means I want to use them >> > in >> > the >> > html-code of an aspx-file. >> > >> > In the above example webAppConstants is a selfdefined java class. But >> > because of "<jsp:useBean..." the class is instantiated to >> > webAppConstants >> > and >> > can be used in the following html-code. >> > >> > I tried the following solution that should give me an object from a >> > session: >> > >> > <%@ Page CodeBehind="Login.aspx.cs" Language="c#" >> > AutoEventWireup="false" >> > Inherits="ReportGenerator.Login" %> >> > <%@ Import namespace="ReportGenerator" %> >> > <% ReportConstants reportConstants = new ReportConstants(); %> >> > <script Language="c#" runat="server"> >> > ReportConstants reportConstants = >> > (ReportConstants)Session["ReportConstants"]; >> > </script> >> > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Tran0sitional//EN" > >> > <HTML> >> > ... >> > >> > But Session is unknown. So how do I get access to the session? Or is >> > what >> > would be another solution. >> > >> > Thanks in advance for any help. >> > >> > Stephen >> >> >> |
|
||
|
||||
|
Sean M
Guest
Posts: n/a
|
I really like this analogy.. can I quote you on it?
"Kevin Spencer" <(E-Mail Removed)> wrote in message news:u2JjT%(E-Mail Removed)... > This is kind of hard to say, but you're putting the cart before the horse > here. What I mean is that, rather than trying to make ASP.Net behave like > Java Beans, or ASP, which is the closest thing in the Microsoft family to > Java Beans. You need to be thinking more about how to accomplish WHAT you > accomplish in Java Beans with ASP.net, not HOW. That is, any programming > technology exists for basically the same purpose: To satisfy requirements, > or to "make something happen." Session State, for example, exists for the > purpose of maintaining state acrosss a single user Session in a stateless > HTTP environment. And indeed, ASP.Net has Session State, and it serves the > same purpose. But you're talking about nailing nails with a hammer gun > instead of a hammer, and you want to know where to hit the nail with the > hammer gun. The end is the same; the means is entirely different. In other > words, you need to either bite the proverbial bullet, and learn how to work > with the ASP.Net object model, or stick with what you know. If you hit nails > with a hammer gun, eventually, the gun breaks. On the other hand, if you use > a hammer gun as it was designed, you can drive a lot more nails in a lot > less time. > > -- > HTH, > > Kevin Spencer > Microsoft MVP > .Net Developer > Ambiguity has a certain quality to it. > > "Stephen H." <(E-Mail Removed)> wrote in message > news:CBF1B33D-86E2-4CB1-8D80-(E-Mail Removed)... > > Hi, > > > > I have an existing web application with java beans that I wanne migrate to > > ASP.NET using C#. > > > > The existing web application has some jsp files that use java beans as > > follows: > > > > ... > > <%@ page language="java" import="reportgen.*"%> > > <%@ page import="java.lang.reflect.Array" %> > > <jsp:useBean id="webAppConstants" scope="session" > > class="reportgen.WebAppConstants"> > > </jsp:useBean> > > <% webAppConstants.loadProperties(config); %> > > <% session.setAttribute("WebAppConstants", webAppConstants);%> > > > > <html> > > <head> > > <title></title> > > ... > > ... > > <td bordercolor="#000000" valign="top"> > > <table width="100%" border="0" cellspacing="0" cellpadding="0" > > height="340" > > class="Text_Small"> > > <tr> > > <td valign="top" height="72"> > > <%out.print(webAppConstants.WELCOME);%> > > <br> > > > > > > Now I'm looking for a possibility to use/make some C# objects that behave > > nearly the same way that java beans do. That means I want to use them in > > the > > html-code of an aspx-file. > > > > In the above example webAppConstants is a selfdefined java class. But > > because of "<jsp:useBean..." the class is instantiated to webAppConstants > > and > > can be used in the following html-code. > > > > I tried the following solution that should give me an object from a > > session: > > > > <%@ Page CodeBehind="Login.aspx.cs" Language="c#" AutoEventWireup="false" > > Inherits="ReportGenerator.Login" %> > > <%@ Import namespace="ReportGenerator" %> > > <% ReportConstants reportConstants = new ReportConstants(); %> > > <script Language="c#" runat="server"> > > ReportConstants reportConstants = > > (ReportConstants)Session["ReportConstants"]; > > </script> > > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Tran0sitional//EN" > > > <HTML> > > ... > > > > But Session is unknown. So how do I get access to the session? Or is what > > would be another solution. > > > > Thanks in advance for any help. > > > > Stephen > > |
|
||
|
||||
|
Kevin Spencer
Guest
Posts: n/a
|
Why thank you Sean. All of my ramblings are copyright-free!
-- :-D, Kevin Spencer Microsoft MVP ..Net Developer Ambiguity has a certain quality to it. "Sean M" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)... >I really like this analogy.. can I quote you on it? > > > "Kevin Spencer" <(E-Mail Removed)> wrote in message > news:u2JjT%(E-Mail Removed)... >> This is kind of hard to say, but you're putting the cart before the horse >> here. What I mean is that, rather than trying to make ASP.Net behave like >> Java Beans, or ASP, which is the closest thing in the Microsoft family to >> Java Beans. You need to be thinking more about how to accomplish WHAT you >> accomplish in Java Beans with ASP.net, not HOW. That is, any programming >> technology exists for basically the same purpose: To satisfy >> requirements, >> or to "make something happen." Session State, for example, exists for the >> purpose of maintaining state acrosss a single user Session in a stateless >> HTTP environment. And indeed, ASP.Net has Session State, and it serves >> the >> same purpose. But you're talking about nailing nails with a hammer gun >> instead of a hammer, and you want to know where to hit the nail with the >> hammer gun. The end is the same; the means is entirely different. In >> other >> words, you need to either bite the proverbial bullet, and learn how to > work >> with the ASP.Net object model, or stick with what you know. If you hit > nails >> with a hammer gun, eventually, the gun breaks. On the other hand, if you > use >> a hammer gun as it was designed, you can drive a lot more nails in a lot >> less time. >> >> -- >> HTH, >> >> Kevin Spencer >> Microsoft MVP >> .Net Developer >> Ambiguity has a certain quality to it. >> >> "Stephen H." <(E-Mail Removed)> wrote in message >> news:CBF1B33D-86E2-4CB1-8D80-(E-Mail Removed)... >> > Hi, >> > >> > I have an existing web application with java beans that I wanne migrate > to >> > ASP.NET using C#. >> > >> > The existing web application has some jsp files that use java beans as >> > follows: >> > >> > ... >> > <%@ page language="java" import="reportgen.*"%> >> > <%@ page import="java.lang.reflect.Array" %> >> > <jsp:useBean id="webAppConstants" scope="session" >> > class="reportgen.WebAppConstants"> >> > </jsp:useBean> >> > <% webAppConstants.loadProperties(config); %> >> > <% session.setAttribute("WebAppConstants", webAppConstants);%> >> > >> > <html> >> > <head> >> > <title></title> >> > ... >> > ... >> > <td bordercolor="#000000" valign="top"> >> > <table width="100%" border="0" cellspacing="0" cellpadding="0" >> > height="340" >> > class="Text_Small"> >> > <tr> >> > <td valign="top" height="72"> >> > <%out.print(webAppConstants.WELCOME);%> >> > <br> >> > >> > >> > Now I'm looking for a possibility to use/make some C# objects that > behave >> > nearly the same way that java beans do. That means I want to use them >> > in >> > the >> > html-code of an aspx-file. >> > >> > In the above example webAppConstants is a selfdefined java class. But >> > because of "<jsp:useBean..." the class is instantiated to > webAppConstants >> > and >> > can be used in the following html-code. >> > >> > I tried the following solution that should give me an object from a >> > session: >> > >> > <%@ Page CodeBehind="Login.aspx.cs" Language="c#" > AutoEventWireup="false" >> > Inherits="ReportGenerator.Login" %> >> > <%@ Import namespace="ReportGenerator" %> >> > <% ReportConstants reportConstants = new ReportConstants(); %> >> > <script Language="c#" runat="server"> >> > ReportConstants reportConstants = >> > (ReportConstants)Session["ReportConstants"]; >> > </script> >> > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Tran0sitional//EN" > >> > <HTML> >> > ... >> > >> > But Session is unknown. So how do I get access to the session? Or is > what >> > would be another solution. >> > >> > Thanks in advance for any help. >> > >> > Stephen >> >> > > |
|
||
|
||||
|
Kevin Spencer
Guest
Posts: n/a
|
Well, Stephen,
I wouldn't be here if I was a pure DIY guy! I'd be off somewhere ignoring the rest of the world. Notice that I did mention that you have the option of sticking with what you know. Otherwise, you're goint o have to put on your thinking cap for a very long time, along with the rest of use exploring this incredibly vast world of .Net technology. But, so you don't feel that I've completely abandoned you to your own devices, I can provide you with a small piece of information regarding the code you posted: >> > <% ReportConstants reportConstants = new ReportConstants(); %> >> > <script Language="c#" runat="server"> >> > ReportConstants reportConstants = >> > (ReportConstants)Session["ReportConstants"]; >> > </script> >> > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Tran0sitional//EN" > >> > <HTML> >> > ... >> > >> > But Session is unknown. So how do I get access to the session? Or is >> > what >> > would be another solution. I would guess that it isn't Session that is "unknown." It looks like Session["ReportConstants"] is null. I don't see where you've initialized it prior to attempting to cast it as a ReportConstants class. -- HTH, Kevin Spencer Microsoft MVP ..Net Developer Ambiguity has a certain quality to it. "Stephen H." <(E-Mail Removed)> wrote in message news:01C48451-14F1-45FE-BAC1-(E-Mail Removed)... > Hi Kevin, > > yes I have to learn more about ASP.Net. But metaphoric answers from people > who seem to come straight out of a DIY store are not really helpfull for > anybody. > > Bernd > > > "Kevin Spencer" wrote: > >> This is kind of hard to say, but you're putting the cart before the horse >> here. What I mean is that, rather than trying to make ASP.Net behave like >> Java Beans, or ASP, which is the closest thing in the Microsoft family to >> Java Beans. You need to be thinking more about how to accomplish WHAT you >> accomplish in Java Beans with ASP.net, not HOW. That is, any programming >> technology exists for basically the same purpose: To satisfy >> requirements, >> or to "make something happen." Session State, for example, exists for the >> purpose of maintaining state acrosss a single user Session in a stateless >> HTTP environment. And indeed, ASP.Net has Session State, and it serves >> the >> same purpose. But you're talking about nailing nails with a hammer gun >> instead of a hammer, and you want to know where to hit the nail with the >> hammer gun. The end is the same; the means is entirely different. In >> other >> words, you need to either bite the proverbial bullet, and learn how to >> work >> with the ASP.Net object model, or stick with what you know. If you hit >> nails >> with a hammer gun, eventually, the gun breaks. On the other hand, if you >> use >> a hammer gun as it was designed, you can drive a lot more nails in a lot >> less time. >> >> -- >> HTH, >> >> Kevin Spencer >> Microsoft MVP >> ..Net Developer >> Ambiguity has a certain quality to it. >> >> "Stephen H." <(E-Mail Removed)> wrote in message >> news:CBF1B33D-86E2-4CB1-8D80-(E-Mail Removed)... >> > Hi, >> > >> > I have an existing web application with java beans that I wanne migrate >> > to >> > ASP.NET using C#. >> > >> > The existing web application has some jsp files that use java beans as >> > follows: >> > >> > ... >> > <%@ page language="java" import="reportgen.*"%> >> > <%@ page import="java.lang.reflect.Array" %> >> > <jsp:useBean id="webAppConstants" scope="session" >> > class="reportgen.WebAppConstants"> >> > </jsp:useBean> >> > <% webAppConstants.loadProperties(config); %> >> > <% session.setAttribute("WebAppConstants", webAppConstants);%> >> > >> > <html> >> > <head> >> > <title></title> >> > ... >> > ... >> > <td bordercolor="#000000" valign="top"> >> > <table width="100%" border="0" cellspacing="0" cellpadding="0" >> > height="340" >> > class="Text_Small"> >> > <tr> >> > <td valign="top" height="72"> >> > <%out.print(webAppConstants.WELCOME);%> >> > <br> >> > >> > >> > Now I'm looking for a possibility to use/make some C# objects that >> > behave >> > nearly the same way that java beans do. That means I want to use them >> > in >> > the >> > html-code of an aspx-file. >> > >> > In the above example webAppConstants is a selfdefined java class. But >> > because of "<jsp:useBean..." the class is instantiated to >> > webAppConstants >> > and >> > can be used in the following html-code. >> > >> > I tried the following solution that should give me an object from a >> > session: >> > >> > <%@ Page CodeBehind="Login.aspx.cs" Language="c#" >> > AutoEventWireup="false" >> > Inherits="ReportGenerator.Login" %> >> > <%@ Import namespace="ReportGenerator" %> >> > <% ReportConstants reportConstants = new ReportConstants(); %> >> > <script Language="c#" runat="server"> >> > ReportConstants reportConstants = >> > (ReportConstants)Session["ReportConstants"]; >> > </script> >> > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Tran0sitional//EN" > >> > <HTML> >> > ... >> > >> > But Session is unknown. So how do I get access to the session? Or is >> > what >> > would be another solution. >> > >> > Thanks in advance for any help. >> > >> > Stephen >> >> >> |
|
||
|
||||
|
Amedee Van Gasse
Guest
Posts: n/a
|
Kevin Spencer shared this with us in
microsoft.public.dotnet.framework.aspnet: > Why thank you Sean. All of my ramblings are copyright-free! # rambling starts here Do you mean Public Domain, Open License, Shared License, Creative Common License, Open Publication license, or some other licensing scam^Wscheme? ;-) -- Amedee Van Gasse |
|
||
|
||||
|
|
|
| |
![]() |
| Thread Tools | |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Converting Java to C# | Jay | Microsoft C# .NET | 10 | 7th Apr 2007 07:05 AM |
| can C# methods call Java/J2EE session beans? | Flip | Microsoft C# .NET | 1 | 19th Mar 2005 11:31 AM |
| Help: how to do equivalent of Java Beans in ASP.NET | =?Utf-8?B?ZG9ubmV0?= | Microsoft ASP .NET | 0 | 12th Jan 2005 10:41 PM |
| .net's altenative to java beans | =?Utf-8?B?c2lja2t5?= | Microsoft Dot NET | 2 | 16th Nov 2004 05:14 PM |
| Calling Java Beans from Visual Basic .NET | Andrea Temporin | Microsoft VB .NET | 1 | 9th Jan 2004 10:41 PM |
Powered by vBulletin®. Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2010, Crawlability, Inc. |




