Solved

FormViews ASP. Net

Posted on 2015-02-12
5
23 Views
Last Modified: 2016-06-23
Using 2 formviews, is there a way to updated sql database using a variable from each formviews.  How do I pass variable from the 1st formview to the 2nd?  I am really new to .net.....so be as clear as possible.
0
Comment
Question by:zraiford
  • 4
5 Comments
 
LVL 33

Accepted Solution

by:
Mike Eghtebas earned 500 total points
Comment Utility
Option 1:
In a module, add:

Public strVar as String

----------
In Form1, set a value to it like

strVar = "ABC"
------------
In Form2, use it

MessageBox.Show(strVar)
0
 
LVL 33

Assisted Solution

by:Mike Eghtebas
Mike Eghtebas earned 500 total points
Comment Utility
There are some other ways of doing this using Friend scope we can discuss later if interested.

I just notice you are not talking about windows application. This was for winForms. For   webform, you can pass the values using session variables.

brb,

Mike
0
 
LVL 33

Assisted Solution

by:Mike Eghtebas
Mike Eghtebas earned 500 total points
Comment Utility
Are you working with vb.net or c#?  I want to create a sample you you but it will be good to know language choice>

Here is partial code:
In webform1, I use  btnSave_Click event to save a phone number (entered into txtPhone control) into a session variable
' and then open Confirm.aspx (the second webform)
Protected Sub btnSave_Click(sender As Object, e As System.EventArgs) Handles btnSave.Click
    Session("phone") = txtPhone.Text
    ' open confirm page
            Response.Redirect("Confirm.aspx")
 End Sub

Open in new window


I wait for your response to continue.

Mike
0
 
LVL 33

Assisted Solution

by:Mike Eghtebas
Mike Eghtebas earned 500 total points
Comment Utility
This is the code in the 1st webform (Default.aspx): You enter a phone number and click on save. It store the value you entered in to a session variable and the opens a second webform (Default2.aspx)
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        Session["phone"] = txtPhone.Text;
        Response.Redirect("Default2.aspx");
    }
}

Open in new window


This the code in the second webform: When this webform opens, it writes the value in the session variable to the page.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Write(Session["phone"]);
    }
}

Open in new window

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now