Using selection in WebForms.

Posted on 2006-04-05
Last Modified: 2008-02-20
I have the following problem: I have "WebForm1". In this WebForm I have some TextBoxex, DropDOwnList, and 3 buttons. In one of the TextBox the user needs to type in a codes product. Beside the TextBox I added a Button in which when the user clicks it I want to open another WebForm or something in which will open a DataGrid with the products that the user can select. And when he select the product the code goes into the TextBox and closes the other WebForm or whatever I make. How can I solve this problem ??? I tried using "UserControl" but I had some problem with it. In fact I addded two questions to see if someone could help me but no one didn´t answer. What is the best way of solving this problem ???? If someone help me, I´ll cancel the other question and add transfer to this question.
Question by:Fredy992
    LVL 1

    Expert Comment

    my best guess would be to upen the pop up, then when the item is selected in the pop up have it re load up the parent page but with a query string with the selection


    goto web form1
    click somthing casuing popup of webform2
    clcik somthing on webform 2, on that click event, redirect("webform.aspx?myData=thingSelected"), and close window
    weform2 frefreshes using the querystring to fill in the data

    Thats my best gues
    LVL 5

    Accepted Solution

    If I follow you correctly.

    You want to fill a textbox of one web form with that of a selection on another web for.

    An Example of how to do this:

    I did this all in Word, no dev enviorment at this computer. So please check for Case/grammer Errors in the code.

    Logic on this.
    1)      Lets create a popup from this window
    2)      Now lets pass to it the name of our control (Textbox) via the query string
    3)      Now on the pop up page lets use javascript to set our controls value

    Page with Textbox

    <INPUT type="button" value="Pick"  onclick="btnClick('TextBox1', 800, 600);">

      <script language="Javascript" >
    function btnClick(){
       var Popup=null;
      settings='width='+ w + ',height='+ h + ',location=no,directories=no,   menubar=no,toolbar=no,status=no,scrollbars=no,resizable=no, dependent=no';

    // The syntax of the method is given below:
    //open (URL, windowName[, windowFeatures])

  ' + ctrl, ‘ProductPage’,  settings);



    ProductList.aspx -Page

      <script language="Javascript" >

            function HaveDVItem(Value) {

    //Get TextboxName from the query string by parsing the string 5
    //’Ctrl=’ is 5 digits
                ctrl =;
    //Set Text box Value by using the textbox name
                thisForm =  window.opener.document.forms[0].elements[ctrl].value = dateValue;
    //Close Form



    Code Behind on Product Page

    ‘Once you have found the item you want simply use registerclientscript to call the javscript function, passing in the value that you want to assign to the textbox
    'Really not sure on syntax here as I don't have intelisense in word, but I think it goes like this.
    Me.clientScript.RegisterClientScript(Me.gettype(), “key1”,  HaveDVItem(MyValue), True)


    Author Comment

    The page to show the other windows I made it and it´s working passing the TextBoxe´s name through the URL. But now I can´t get the other window (ProductList.aspx) pass the value of the TextBox in the ProductList.aspx to the first WebForm when the user cliks on the button. The code you posted:

    Me.clientScript.RegisterClientScript(Me.gettype(), “key1”,  HaveDVItem(MyValue), True)

    Is not working. It´s giving me alot of syntax error

    Author Comment

    Another question. Why in the "oncLick" ´s button you put:

    btnClick('TextBox1', 800, 600)

    If in the function you don´t have to pass any parameters ???

    function btnClick(){
       var Popup=null;
    LVL 5

    Expert Comment

    Woops COde Error

    function btnClick(){

    Should of read function btnClick(ctrl,w,h){


    Heres the correct Code Behind

    Easier when i have VS

        Dim MyValue As String = "Somthing I want to set"
            Me.ClientScript.RegisterStartupScript(Me.GetType(), "key1", "HaveDVItem(" & MyValue & ")", True)

    Author Comment

    I´m using C# so I changed to:

    this.RegisterStartupScript(this.GetType(),"key1","HaveDVItem(" + MyValue + ")",true);

    withou the "ClientScript" because it seems not to have this. But now it´s giving me a compile erros saying:

    "No overload for method 'RegisterStartupScript' takes '4' arguments"

    What´s wrong with my code ????

    Author Comment

    And a last this. How can I change the code:

    ctrl =;

    To get the right string because I need to pass more than one string. I´m passing for example:"ProductList.aspx?Ctrl=" + ctrl + "&TypeCode=C", "Equipamento" ,settings)

    So when I get to the other form it can´t find the "Ctrl".

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Join & Write a Comment

    One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on could not pull conte…
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    729 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

    18 Experts available now in Live!

    Get 1:1 Help Now