Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to pass values from page to page

Status
Not open for further replies.

Ken011

MIS
Oct 13, 2006
66
US
greetings good experts.

In classic asp, I would pass values via hidden form or query string.

Can someone please show me how this is done in asp.net?

I am using vb.net version 2.0 and I am working with vs.2003

So far, anything I tried has failed.

I am trying to pass only 6 values from page1.aspx to page2.aspx. 2 of those values is checkboxList.

Here is an example of what I am trying to do.

Code:
Option Explicit On 
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Xml
Imports System.Web
Imports System.Drawing
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports System.Web.UI.Page
Imports Microsoft.VisualBasic
Imports System.Web.HttpApplication
Imports System.Web.HttpResponse


Public Class _default
    Inherits System.Web.UI.Page

    Protected WithEvents txtAuthName As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtservice As System.Web.UI.WebControls.checkBoxList
    Protected WithEvents txtcheck As System.Web.UI.WebControls.checkBoxList

    Protected WithEvents txtAuthJob As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtAuthPhone As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtservice As System.Web.UI.WebControls.CheckBoxList
    Protected WithEvents txtccCheck As System.Web.UI.WebControls.CheckBoxList
    Protected WithEvents btnSave As System.Web.UI.WebControls.Button
    Protected WithEvents txtAuthEmail As System.Web.UI.WebControls.TextBox
#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents service As System.Web.UI.WebControls.CheckBoxList
    Protected WithEvents ccCheck As System.Web.UI.WebControls.CheckBoxList
    Protected WithEvents AuthName As System.Web.UI.WebControls.TextBox
    Protected WithEvents AuthJob As System.Web.UI.WebControls.TextBox
    Protected WithEvents AuthPhone As System.Web.UI.WebControls.TextBox
    Protected WithEvents AuthEmail As System.Web.UI.WebControls.TextBox
    Protected WithEvents submit As System.Web.UI.WebControls.Button
    Protected WithEvents Form1 As System.Web.UI.HtmlControls.HtmlForm

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
        Me.txtAuthName.Text = Request.QueryString("AuthName")
        Me.txtService.Text = Request.QueryString("cService")
        Me.txtcCheck.Text = Request.QueryString("cCheck")

        Me.txtAuthJob.Text = Request.QueryString("AuthJob")
        Me.txtAuthPhone.Text = Request.QueryString("AuthPhone")
        Me.txtAuthEmail.Text = Request.QueryString("AuthEmail")
    End Sub
    Private Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Response.Redirect("requesters.aspx?" + "&AuthName=" + Server.UrlEncode(Me.txtAuthName.Text) 
+ "&cService=" + Server.UrlEncode(Me.txtCheck.Text) 
+ "&cCheck=" + Server.UrlEncode(Me.txtAuthName.Text) 
+ "&AuthJob=" + Server.UrlEncode(Me.txtAuthJob.Text) + "&AuthPhone=" + Server.UrlEncode(Me.txtAuthPhone.Text) + "&AuthEmail=" + Server.UrlEncode(Me.txtAuthEmail.Text))
    End Sub

This is not working.

I am getting an error that the way I am doing checkboxlist is incorrect. Please. please help!

Thanks in advnance
End Class
 
Oh, I see what you are doing now. Very strange naming convention you have there as you have CheckBoxList's prefixed with "txt"!

As it isn't a TextBox you can't use the Text property so if you want to get the value from a CheckBoxList you have to use SelectedItem.Value or loop through the Items collection and check which items are selected.



____________________________________________________________
Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]

Need help finding an answer? Try the Search Facility or read FAQ222-2244.
 
ca8msm,

Thank you for your prompt response.

I made the changes you recommended and the errors went away.

However, when I entered values into page1.aspx and clicked the Submit button, I was expecting it to take me to page2.aspx but instead, it remained on page1.aspx.

Can you please tell me what I am doing wrong?

I am completely new in .net.

Thank you for your help.
 
You have no Handles directive on the end of your click event so I'm assuming the function isn't being called. You can debug the application and step through the code to see if this is the case or not.


____________________________________________________________
Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]

Need help finding an answer? Try the Search Facility or read FAQ222-2244.
 
ok, I have added the Handles = Handles Btn_save.Click.

Now, it is taking me to page2.asp.

But I am getting this error below:


Object reference not set to an instance of an object.

The error is caused by the checkBoxList. Apparently, what I thought would work did not.

If I remove the 2 checkBoxList items, it will works fine.

What is the correct solution?

This is what I have tried.

Protected WithEvents txtcService As System.Web.UI.WebControls.CheckBoxList
Protected WithEvents txtcCheck As System.Web.UI.WebControls.CheckBoxList

Then this:

Private Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
Response.Redirect("requesters.aspx?" + "&AuthName=" + Server.UrlEncode(Me.txtAuthName.Text) + "&cService=" + Server.UrlEncode(Me.txtcService.SelectedValue) + "&cCheck=" + Server.UrlEncode(Me.txtcCheck.SelectedValue) + "&AuthJob=" + Server.UrlEncode(Me.txtAuthJob.Text) + "&AuthPhone=" + Server.UrlEncode(Me.txtAuthPhone.Text) + "&AuthEmail=" + Server.UrlEncode(Me.txtAuthEmail.Text))
End Sub

Do you know how I can resolve this?

Thanks again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top