Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

Thursday, March 29, 2012

newbie - keeping my object data as page refreshes

Hi all

I have some experience in 'Windows' programming but I am new to Web
programming, I wonder if anyone can help.

I have a middle layer object that brings some data from a database class .
The class reprsents a Callout, has lots of methods and properties and
manages the business logic..

I then have a html page (GUI layer) that creates an instance of a callout,
and from the callout object, it displays some textfields, labour etc plus
some datagrids based on some collections it holds.

Everything works fine until the page refreshes, at which time the object
seems to be destroyed and then recreated.

I want to keep the object alive with its existing data, on the server, and
connect back to it , ie. not create a new object each time. I know I could
use my Callouts WriteDate event to persist the data back to the SQLServer,
and then just re load it, but this isn't what I really want. I would like to
keep the object live until all work has been completed.

I have read a few things about sessions states etc, but don't really know
where to start, and how to make the class persist.

initially I had

public partial class CallOutDetail : System.Web.UI.Page
{
ExistingCallout Currentcallout;
int m_CalloutPK = 0;

protected void Page_Load(object sender, EventArgs e)
{
m_CalloutPK = 1212;
Currentcallout = new ExistingCallout(m_CalloutPK);

I have tried putting the Currentcallout in not postback i.e.

public partial class CallOutDetail : System.Web.UI.Page
{
ExistingCallout Currentcallout;
int m_CalloutPK = 0;

protected void Page_Load(object sender, EventArgs e)
{
m_CalloutPK = 1212;
if (!IsPostBack)
{
// first time
Currentcallout = new ExistingCallout(m_CalloutPK);
SetLabour();
SetMaterials();
}

Any pointers would be welcome

thanks

Andycouple options...
both require that it be serialized

you can place it in the Page's viewstate...

private constant vs_callout="A";

protected CalloutType CurrentCallout{
get{return this.ViewState[vs_callout] as CalloutType;}
set{this.ViewState[vs_callout] = value;}
}

...or place it in the session
}

"AAJ" wrote:

Quote:

Originally Posted by

Hi all
>
I have some experience in 'Windows' programming but I am new to Web
programming, I wonder if anyone can help.
>
I have a middle layer object that brings some data from a database class .
The class reprsents a Callout, has lots of methods and properties and
manages the business logic..
>
I then have a html page (GUI layer) that creates an instance of a callout,
and from the callout object, it displays some textfields, labour etc plus
some datagrids based on some collections it holds.
>
Everything works fine until the page refreshes, at which time the object
seems to be destroyed and then recreated.
>
I want to keep the object alive with its existing data, on the server, and
connect back to it , ie. not create a new object each time. I know I could
use my Callouts WriteDate event to persist the data back to the SQLServer,
and then just re load it, but this isn't what I really want. I would like to
keep the object live until all work has been completed.
>
I have read a few things about sessions states etc, but don't really know
where to start, and how to make the class persist.
>
initially I had
>
public partial class CallOutDetail : System.Web.UI.Page
{
ExistingCallout Currentcallout;
int m_CalloutPK = 0;
>
protected void Page_Load(object sender, EventArgs e)
{
m_CalloutPK = 1212;
Currentcallout = new ExistingCallout(m_CalloutPK);
>
>
I have tried putting the Currentcallout in not postback i.e.
>
public partial class CallOutDetail : System.Web.UI.Page
{
ExistingCallout Currentcallout;
int m_CalloutPK = 0;
>
protected void Page_Load(object sender, EventArgs e)
{
m_CalloutPK = 1212;
if (!IsPostBack)
{
// first time
Currentcallout = new ExistingCallout(m_CalloutPK);
SetLabour();
SetMaterials();
}
>
>
Any pointers would be welcome
>
thanks
>
Andy
>
>
>


thanks David

"David Jessee" <DavidJessee@.discussions.microsoft.comwrote in message
news:CF0F5237-8616-4C4B-9DA9-252BA0946C1D@.microsoft.com...

Quote:

Originally Posted by

couple options...
both require that it be serialized
>
you can place it in the Page's viewstate...
>
private constant vs_callout="A";
>
protected CalloutType CurrentCallout{
get{return this.ViewState[vs_callout] as CalloutType;}
set{this.ViewState[vs_callout] = value;}
}
>
...or place it in the session
}
>
>
>
"AAJ" wrote:
>

Quote:

Originally Posted by

>Hi all
>>
>I have some experience in 'Windows' programming but I am new to Web
>programming, I wonder if anyone can help.
>>
>I have a middle layer object that brings some data from a database class
>.
>The class reprsents a Callout, has lots of methods and properties and
>manages the business logic..
>>
>I then have a html page (GUI layer) that creates an instance of a
>callout,
>and from the callout object, it displays some textfields, labour etc plus
>some datagrids based on some collections it holds.
>>
>Everything works fine until the page refreshes, at which time the object
>seems to be destroyed and then recreated.
>>
>I want to keep the object alive with its existing data, on the server,
>and
>connect back to it , ie. not create a new object each time. I know I
>could
>use my Callouts WriteDate event to persist the data back to the
>SQLServer,
>and then just re load it, but this isn't what I really want. I would like
>to
>keep the object live until all work has been completed.
>>
>I have read a few things about sessions states etc, but don't really know
>where to start, and how to make the class persist.
>>
>initially I had
>>
>public partial class CallOutDetail : System.Web.UI.Page
>{
>ExistingCallout Currentcallout;
>int m_CalloutPK = 0;
>>
>protected void Page_Load(object sender, EventArgs e)
>{
>m_CalloutPK = 1212;
>Currentcallout = new ExistingCallout(m_CalloutPK);
>>
>>
>I have tried putting the Currentcallout in not postback i.e.
>>
>public partial class CallOutDetail : System.Web.UI.Page
>{
>ExistingCallout Currentcallout;
>int m_CalloutPK = 0;
>>
>protected void Page_Load(object sender, EventArgs e)
>{
>m_CalloutPK = 1212;
>if (!IsPostBack)
>{
>// first time
>Currentcallout = new ExistingCallout(m_CalloutPK);
>SetLabour();
>SetMaterials();
>}
>>
>>
>Any pointers would be welcome
>>
>thanks
>>
>Andy
>>
>>
>>

Newbie : SMTP Problem

Hi,

I'm a newbie in programming. I have started working on ASP.Net this week. My OS is Windows XP Profesional. IIS 5.1, Visual Studio 2005. I am trying to build a simple user login system from the book "ASP.Net 2.0 Everyday Apps for DUMMIES". I followed every instruction written in the book. Everything is working well apart from sending email to the user while registering or changing password.

Can anyone help me please. Thanx in Advance,

Portion of webconfig file is below:

<system.net>
<mailSettings>
<smtp>
<network host="localhost" port="25" />
</smtp>
</mailSettings>
</system.net>

The error I'm getting is below.

Server Error in '/UserLoginCS' Application.

Mailbox unavailable. The server response was: 5.7.1 Unable to relay forcupidoly@dotnet.itags.org.gmail.com

Description:An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details:System.Net.Mail.SmtpFailedRecipientException: Mailbox unavailable. The server response was: 5.7.1 Unable to relay forcupidoly@dotnet.itags.org.gmail.com

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.


Stack Trace:

[SmtpFailedRecipientException: Mailbox unavailable. The server response was: 5.7.1 Unable to relay for cupidoly@dotnet.itags.org.gmail.com] System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException& exception) +704 System.Net.Mail.SmtpClient.Send(MailMessage message) +2184 System.Web.UI.WebControls.LoginUtil.SendPasswordMail(String email, String userName, String password, MailDefinition mailDefinition, String defaultSubject, String defaultBody, OnSendingMailDelegate onSendingMailDelegate, OnSendMailErrorDelegate onSendMailErrorDelegate, Control owner) +482 System.Web.UI.WebControls.CreateUserWizard.AttemptCreateUser() +639 System.Web.UI.WebControls.CreateUserWizard.OnNextButtonClick(WizardNavigationEventArgs e) +199 System.Web.UI.WebControls.Wizard.OnBubbleEvent(Object source, EventArgs e) +649 System.Web.UI.WebControls.CreateUserWizard.OnBubbleEvent(Object source, EventArgs e) +157 System.Web.UI.WebControls.WizardChildTable.OnBubbleEvent(Object source, EventArgs args) +39 System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +56 System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +107 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +178 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +31 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +32 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +72 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3840



Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.42

Is your PC a email server?If not,you should set a email server in web.config.Besides,can you paste some codes about how do you send emails?

I'm also getting the same error. This error only occurs when email address does not exists.

Error displayed: Server Error in '/' Application. ------------------------ Runtime Error Mailbox unavailable. The server response was: 5.1.1 User unknown Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Net.Mail.SmtpFailedRecipientException: Mailbox unavailable. The server response was: 5.1.1 User unknown Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. Stack Trace: [SmtpFailedRecipientException: Mailbox unavailable. The server response was: 5.1.1 User unknown] System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException& exception) +800307 System.Net.Mail.SmtpClient.Send(MailMessage message) +2004 System.Web.UI.WebControls.LoginUtil.SendPasswordMail(String email, String userName, String password, MailDefinition mailDefinition, String defaultSubject, String defaultBody, OnSendingMailDelegate onSendingMailDelegate, OnSendMailErrorDelegate onSendMailErrorDelegate, Control owner) +341 System.Web.UI.WebControls.CreateUserWizard.AttemptCreateUser() +571 System.Web.UI.WebControls.CreateUserWizard.OnNextButtonClick(WizardNavigationEventArgs e) +105 System.Web.UI.WebControls.Wizard.OnBubbleEvent(Object source, EventArgs e) +453 System.Web.UI.WebControls.CreateUserWizard.OnBubbleEvent(Object source, EventArgs e) +149 System.Web.UI.WebControls.WizardChildTable.OnBubbleEvent(Object source, EventArgs args) +17 System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35 System.Web.UI.WebControls.ImageButton.OnCommand(CommandEventArgs e) +115 System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String eventArgument) +171 System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102

Saturday, March 24, 2012

Newbie Forms Question

Hello All -

I have intermediate experience with MS SQL 2000 Server Programming and now getting into .net, ASP.net, VB.net and ADO.net to be more specific.
I was given this simple project to build a data entry form to insert some data in a SQL table. I have the form ready and need some help on how to take the data from my form (text box, drop downs) and send to my sql table, I've read some articles about data adapter but still not sure how to use that.
I'm also consfused between using the code on the web page or the code behind.

Any light you guys can shed will be welcome, thanks in advance.

Depends on what version of ASP.NET you're working with. If using 2.0, then I suggest you read through the following. Lots of info there with examples...

http://www.asp.net/QuickStart/aspnet/Default.aspx

Newbie help with RadioButtonList

Hi, I have only been at this for a few days, so please bear with me as I have no previous programming experience at all.

I am trying to create a simple Exchange Rate converter for our company.

Please find attached code


Function getrate() As System.Data.IDataReader
Dim connectionString As String = "server='(local)\netsdk'; trusted_connection=true; database='Exchange_Rate_Convert"& _
"er'"
Dim dbConnection As System.Data.IDbConnection = New System.Data.SqlClient.SqlConnection(connectionString)

Dim queryString As String = "SELECT [Rates].* FROM [Rates]"
Dim dbCommand As System.Data.IDbCommand = New System.Data.SqlClient.SqlCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection

dbConnection.Open
Dim dataReader As System.Data.IDataReader = dbCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection)

Return dataReader
End Function

Sub Page_Load(sender As Object, e As EventArgs)
if not page.ispostback then
rates.datasource = getrate()
rates.databind()

rates1.datasource = getrate()
rates1.databind()
end if
End Sub

Sub rates_SelectedIndexChanged(sender As Object, e As EventArgs)

currencytxt.text = " " & rates.selecteditem.text

End Sub

Sub rates1_SelectedIndexChanged(sender As Object, e As EventArgs)

finaltxt.text = ((value_to_convert.text / rates.selecteditem.value) * rates1.selecteditem.value)
End Sub

I have 3 questions:

Question 1:

Everything works as I expected it to if the user uses it once, Enter value -> click on first currency -> click on second currency.

However if they (Perhaps) realized they made a mistake with the first currency click again, then the "Finaltxt.txt value" is not correct.

What I would like to do is to allow as many different button clicks from both sets of Radiobuttonlist's as they care to use and have "Finaltxt.txt value" updated every time a new button is pressed. - I also imagine they may keep the browser open all day and use it perodicaly.

Question 2:

I am not really sure that I should be doing "Maths" from data held in a text box. (I would have assumed this data to be a string, however it does work, I would have thought I would need to convert it in some way but I can't find an appropriate command/syntax.

Question 3:

How do I format the value shown in "Finaltxt.txt value", I would like this figure to be rounded up to two decimal places.

I would appreciate any help given.

Best wishes.

James.perhaps u should have a command button to do the actual conversion

Thursday, March 22, 2012

newbie issue

Hi all,
I'm new to the concept of ASP programming but still "I'm not ignorant"...
I was working on a guest book, I've done everything, but I don't know how to save content of a textbox into file (Append).

P.S.
1- I'm using ASP .NET 2 VS 2005
2- The programming language is not a problem

Thanks in advancehttp://support.microsoft.com/default.aspx?scid=kb;EN-US;816149

But for a guestbook, why not use a database? Files are rather inefficient, but hey, it's your website.
http://support.microsoft.com/default.aspx?scid=kb;EN-US;816149

But for a guestbook, why not use a database? Files are rather inefficient, but hey, it's your website.
The site doesn't contain anything about ASP
1. ASP.NET isn't a programming language, it is a technology. You still use a codebehind language such as VB.NET or C#.

2. The syntax will be just about the same for you in 2.0.

3. If you are viewing that page in Firefox, it is broken. Scroll down until you see the floating islands of code.
1. ASP.NET isn't a programming language, it is a technology. You still use a codebehind language such as VB.NET or C#.

I knew someone is gonna say that, so I said "I'm not ignorant" :p

2. The syntax will be just about the same for you in 2.0.

I don't understand what does this mean!

3. If you are viewing that page in Firefox, it is broken. Scroll down until you see the floating islands of code.

I'm using FF and I saw the code (what's a floating island? :confused: )

My problem is "I know how to write to a file, but how can I use a file in one of my web folders?"
Use a file... can you explain that?
It's very simple, I have a file that I use for read-write... (It contains Guests messages to read & new messages are appended to it)
The thing is, in what path should I store it so I can read from it and write to it without getting the "Access Denied" Exception
In regular VB I use the property Application.WorkingDirectory to get the current path, is there an equivalent in ASP?
Ideally, should be the same path as the asp.net application.

Use Server.Mappath().