将用户重定向到新页面 [英] redirecting user to a new page

查看:91
本文介绍了将用户重定向到新页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 我有一个网页(page1.aspx),该网页使用类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


现在,如果我使用response.redirect方法进行重定向,则
调用sendingobject属性时,将引发Nullreference异常.

并且,如果我使用calculate按钮的postbackurl属性,则在两种情况下都将回发邮件(即使文本框为空).


还有其他方法可以实现这一目标.
或我需要在上面的代码中进行一些更正..

预先感谢thanx

解决方案

这是您的问题

newob1=PreviousPage.SendingObject

您不能像这样从page1访问对象.请记住,网络是无状态的,因此您每次都需要重建对象.


您要做的是,将page1的计算结果保存到会话"中,然后可以在page2上将其取回

第1页:

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



第2页:

'' You would need to convert Session["result"] into appropriate type.
lbl1.text= Session["result"]


您好

可以在不使用会话状态的情况下将值从一页传递到另一页.请参考以下URL,但不要使用服务器重定向,请使用将对象实际发布到下一页的回发URL.

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

但是,要控制回发,请在OnClientClick事件上使用javascript,仅当textbox1具有值时才应返回true.如果javascript返回false,它将不会回发


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

解决方案

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"]


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


这篇关于将用户重定向到新页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆