Click here to Skip to main content
15,921,694 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi i have a webpage(page1.aspx) that performs calculations using a object of a class say class1.

'page 1.aspx.vb contains

dim ob1 as new class1

Public ReadOnly Property SendingObject() As class1
        Get
            SendingObject = ob1
        End Get
    End Property

Private Sub cmdCalculate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdCalculate.Click

if textbox1.text="" then
label1.text="please enter a value"
else
ob1.calculate()
'here i want to redirect the user to new page(page2.aspx)
End Sub

''page2.aspx.vb contains

dim  newob1 As class1

page_load event

newob1=PreviousPage.SendingObject

dim lbl1 as new label
lbl1.id="somename"
lbl1.text=newob1.result

panel1.controls.add(lbl1)

end sub

now if i use the response.redirect method to redirect then
while calling the sendingobject property Nullreference exception is thrown.

and if i use the postbackurl property of the calculate button then it gets post backed in both the cases(even if the textbox is blank).


is there any other method to achieve this.
or some correction that i need to do in the above code..

thanx in advance
Posted
Updated 10-Feb-11 4:58am
v3

Here is your problem

newob1=PreviousPage.SendingObject

You can't access objects from page1 just like that. Remember the web is stateless, thus you need to rebuild your objects every time.


what you want to do is, save the calculation result of page1 into, say Session, then you can retireive it on page2

page 1:

'Do you calculation
Session["result"] = ob1.calculate()


Page 2:
' You would need to convert Session["result"] into appropriate type.
lbl1.text= Session["result"]
 
Share this answer
 
Hi

It is possible to pass values from one page to another page without using session state. Refer the following url, but not use server redirect, use the postback url which actually post the object to the next page.

http://msdn.microsoft.com/en-us/library/6c3yckfw.aspx[^]

However to have control on postback have a javascript on the OnClientClick event which should return true only if the textbox1 has a value. If the javascript return false it won't post back
 
Share this answer
 
Comments
aruna_0990 10-Feb-11 21:14pm    
hey..
actually i was trying that...
now on the click event of calculate button i have written this code:

<script type ="text/javascript" >
function validate()
{
if (document .getElementById ('textbox1').value.length==0)
{
document .getElementById ('label1').innerText ='please enter a value';
document .getElementById ('textbox1').focus();

return false;


}
else
{
return true ;

}
}
aruna_0990 10-Feb-11 21:16pm    
but in this case it is posted back to the same page(i.e page1.aspx) and doesn't go to page2.aspx even if there is an entry..

can u suggest me something...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900