Solved

FormViews ASP. Net

Posted on 2015-02-12
5
33 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
5 Comments
 
LVL 34

Accepted Solution

by:
Mike Eghtebas earned 500 total points
ID: 40607368
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 34

Assisted Solution

by:Mike Eghtebas
Mike Eghtebas earned 500 total points
ID: 40607371
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 34

Assisted Solution

by:Mike Eghtebas
Mike Eghtebas earned 500 total points
ID: 40607385
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 34

Assisted Solution

by:Mike Eghtebas
Mike Eghtebas earned 500 total points
ID: 40607401
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

730 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