Quantcast
Channel: Visual Studio and Visual Web Developer Express
Viewing all articles
Browse latest Browse all 3509

Help with returning value from window when it closes

$
0
0

I'm using Visual Web Developer 2010 Express with SQL Server 2008 Express, VB.

I have the routine below that interrupts ItemUpdating to check the validity of the value in PCB_FootprintTextBox. It checks against a database of footprint names and if no match is found it sends the footprint name to footprints.aspx.  Footprints.aspx should give users the option to accept the name (it will then be entered into the database as a new footprint and continue the ItemUpdating routine), edit the name (and return it) or select a name from a dropdownlist (and return it).  Other than accepting the name should result in canceling the ItemUpdating routine.

It sends the value to Footprints.aspx through the "ScriptManager.RegisterStartupScript(Me, Me.GetType(), "popup", script, True)" line and it is correctly received by footprints.aspx.

The problem I'm having is getting footprints.aspx to return a value.  Below is the routing sending the value to footprints.aspx:

  Public Shared ParamA As String = String.Empty
    Public Shared MyArgs As String = String.Empty

Protected Sub FormView1_ItemUpdating(sender As Object, e As System.Web.UI.WebControls.FormViewUpdateEventArgs) Handles FormView1.ItemUpdating 'Find default value suffixes and verify/change entered data Dim sqlConnection As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("conCString1").ConnectionString) Dim Prt As String = String.Empty Dim Fval As TextBox = FormView1.FindControl("PCB_FootprintTextBox") Dim X As Integer = 0 Dim Y As Integer = 0 'Determine if string is single or multiple listing X = InStr(Fval.Text, ",") If X = 0 Then Dim cmd As New SqlCommand cmd.CommandType = CommandType.Text cmd.Connection = sqlConnection Dim querystring As String = "SELECT [Footprint] FROM [Combined Footprints] WHERE ([Footprint] = '" & Fval.Text & "')" sqlConnection.Open() Dim command As New SqlCommand(querystring, sqlConnection) Dim reader As SqlDataReader = command.ExecuteReader() While reader.Read() Prt = reader(0).ToString End While sqlConnection.Close() If Prt <> Fval.Text Then 'Verify user wants new footprint or oopsed and offer list of similarities ParamA = Fval.Text MyArgs = ParamA Dim script As String = "window.showModalDialog('Footprints.aspx', '" & MyArgs & "','height=800,width=800', 'scrollbars=yes');" ScriptManager.RegisterStartupScript(Me, Me.GetType(), "popup", script, True) ' 'if value returned = value sent then update combined footprints and continue with update/insert ' ' 'if value returned <> value sent then cancel update, user must re-submit ' e.Cancel = True End If If Prt = Fval.Text Then 'Footprint exists so continue to itemupdated/inserted End If End If If X <> 0 Then End If End Sub

Below if footprints.aspx:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Footprints.aspx.vb" EnableEventValidation = "false" Inherits="Footprints" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"><title></title><script language="javascript", type="text/javascript">
        function Done() {
            var ParamA = tbParamA.value;
            var MyArgs = ParamA;
            window.returnValue = MyArgs;
            window.close();
        }
        function DoneX() {
            var e = document.getElementById("DropDownList2");
            var f = "-- Select footprint --"
            if (e.options[e.selectedIndex].text != f) tbParamA.value = e.options[e.selectedIndex].text;
            var ParamA = tbParamA.value;
            var MyArgs = ParamA;
            window.returnValue = MyArgs;
            window.close();
        }
        function doInit() {
            var ParamA = "Aparm";
            var MyArgs = ParamA;
            MyArgs = window.dialogArguments;
            tbParamA.value = MyArgs.toString();
        }
        function tbParamA_onclick() {

        }
        function DoneY() {
            var e = document.getElementById("DropDownList2");
            var f = "-- Select footprint --"
            if (e.options[e.selectedIndex].text != f) tbParamA.value = e.options[e.selectedIndex].text;
        }</script></head><body onload="doInit()"><form id="form1" runat="server"><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<asp:Label ID="Label3" runat="server" Font-Bold="True" Font-Size="Larger" 
            Text="Footprint Verification"></asp:Label></p><p>This window has opened because the listed footprint is either NEW or has been 
        incorrectly entered.</p><p>If this footprint is new and correct as entered simply press OK, or you can edit 
        it if necessary. Edited entries will return to part, unchanged entries will 
        continue with Update/Insert operation.</p><p>If this footprint name has been incorrectly entered please select a footprint 
        from the dropdown list and press Continue to continue with Update/Insert 
        operation.</p><p><asp:Label ID="Label4" runat="server" Text="NEW footprint?" Width="125px"></asp:Label><input id="tbParamA" type="text" onclick="return tbParamA_onclick()" />&nbsp;<button onclick="Done()" type="button">&nbsp;OK</button>&nbsp;(function Done)</p><p><asp:Label ID="Label2" runat="server" Text="Selected footprint:" 
            Width="125px"></asp:Label><asp:DropDownList ID="DropDownList2" runat="server" Width="350px" 
            AutoPostBack="True" DataSourceID="SqlDataSource1" DataTextField="Footprint" 
            DataValueField="Footprint"></asp:DropDownList>&nbsp;<button onclick="DoneX()" type="button">&nbsp;Continue</button>&nbsp; (function DoneX)</p><asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:CRAPConnectionString299 %>" 
        SelectCommand="SELECT [Footprint] FROM [Combined Footprints] ORDER BY [Footprint]"></asp:SqlDataSource><br /><asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><button onclick="DoneY()" type="button">&nbsp;Test</button>&nbsp;(remove along with function DoneY)</form></body></html>

Below is footprints.aspx.vb:

Imports System.IO
Imports System.Data
Imports System.Drawing
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Text
Imports System.Collections.Generic
Imports System.Linq
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.Control
Imports System.Web.UI.WebControls.Label
Imports System.Web.UI.WebControls.TextBox
Imports System.Web.UI.HtmlTextWriter
Imports System.Web.UI.WebControls.FormView

Partial Class Footprints
    Inherits System.Web.UI.Page

    Protected Sub DropDownList2_DataBound(sender As Object, e As System.EventArgs) Handles DropDownList2.DataBound
        DropDownList2.Items.Insert(0, New ListItem("-- Select footprint --"))
    End Sub

End Class

I'm at the point of being bewildered, befuddled and totally confused. :) (Not to mention getting a headache.)

Hopefully somebody can see where I'm missing something and offer the solution or point me in the right direction.

Thanks!


Viewing all articles
Browse latest Browse all 3509

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>