Women in Technology

Hear us Roar



Article:
  Enhancing ASP.NET Pages with JavaScript
Subject:   Need help with popup box (lookup).
Date:   2007-08-26 05:25:53
From:   yasinirshad
I have a form with textbox. Besides this textbox i should have imagebutton / something which on clicking will open a popup window (lookup). This popup window will have UserId and Usernames (from db). So when the User selects one from this , the UserId should get selected in the textbox. How to do this? Please help. Can you please send me a sample of this type ..? Its very urgent.
Thanks lot..
Full Threads Oldest First

Showing messages 1 through 1 of 1.

  • Need help with popup box (lookup).
    2007-09-21 01:15:43  sunithashukla [View]

    In first page source code write code in Script as
    <script type="text/javascript" language="javascript">
    function getId(ControlId,UserName)
    {
    document.getElementById(ControlId).value = UserName;
    }
    </script>
    ......
    and next go to .cs of same page and write code as
    protected void Page_Load(object sender, EventArgs e)
    {
    lnkbt.OnClientClick = "window.open('GridView.aspx?ControlId=" + txtName.ClientID + "')";
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
    Response.Write("<script>alert('Hai')</script>");
    }
    ...........
    Go to next page and write below code in source code as
    <script type="text/javascript" language="javascript">
    function getData(ControlId,UserName)
    {
    window.opener.getId(ControlId,UserName);
    window.close();
    }
    </script>
    ................
    next go to .cs of this page 2 and write code as
    protected void Page_Load(object sender, EventArgs e)
    {
    DataTable dt = new DataTable();
    dt.Columns.Add("UserId");
    dt.Columns.Add("UserName");
    dt.Columns.Add("Password");
    dt.Columns.Add("EmailId");

    dt.Rows.Add("1", "Ravi", "Ravi", "Ravi@gmail.com");
    dt.Rows.Add("2", "Rama", "Rama", "Rama@gmail.com");
    dt.Rows.Add("3", "Ramu", "Ramu", "Ramu@gmail.com");
    dt.Rows.Add("4", "Rao", "Rao", "Rao@gmail.com");



    GridView1.DataSource = dt;
    GridView1.DataBind();
    }

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
    LinkButton lnkSelect = (LinkButton)e.Row.FindControl("lnkselect");
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
    lnkSelect.OnClientClick = "getData('" + Request.QueryString["ControlId"].ToString() + "','" + e.Row.Cells[1].Text + "');";
    //lnkSelect.OnClientClick = "test();";
    }
    }
    }
    ..................
    Actually in this senario when we run the program and click on a button it will redirect to other page with in the window ie a popup box.In this window if we click on any row of gridview column then this window 2 will close and id will display in page 1 at textbox.
    I think so this is correct answer .