如何使用JavaScript来传递从父asp.net的DropDownList值文本框在弹出 [英] How to pass value from parent asp.net dropdownlist to textbox in popup using javascript

查看:237
本文介绍了如何使用JavaScript来传递从父asp.net的DropDownList值文本框在弹出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我未能从DropDownList的父ASPX形式传递值文本框的子ASPX形式

Hello i am failing to pass the value from dropdownlist in the parent aspx form to textbox in the child aspx form

父的javascript
:第一个脚本是打开弹出式窗口

Parent javascript : The First script is to open the popup window

    <script type="text/javascript">
     var popup;
       function NewCustOpn() {
      popup = window.open("NewCustomer.aspx","Popup",toolbar=no,scrollbars=no,location=no,statusbar=no,menubar=no,resizable=0,width=520,height=350,left = 250,top = 50");

 }
   </script>

这是父页面上的第二个脚本拿到的DropDownList的值

This is the second script on the parent page to get the value of the dropdownlist

    <script type = "text/javascript">
    function parentFunc()
    {
        return document.getElementById ("<%=DropDownList1.ClientID%>").value;
    }

  </script>

子页面的JavaScript:

The child page javascript:

      <script type = "text/javascript">
    window.onload = function ()
    {

        if(window.opener != null && !window.opener.closed)  
        {
           var val = window.opener.parentFunc();
      var textbox = document.getElementById("<%=TextBox1.ClientID%>");
           textbox.Value = val; 
        }
    }
    </script>

在弹出的打开TextBox1的是空的。

When the popup opens TextBox1 is empty.

推荐答案

您的问题很简单。刚刚从你的孩子页面的js函数替换下面的行

Your problem is simple. Just replace the below line from your child page's js function

textbox.Value = val;

textbox.value = val; // lowercase "v"

或justdo直接分配这样

or justdo a direct assignment like this

document.getElementById("<%=TextBox1.ClientID%>").value = val;

或者另一种可能的解决办法是直接传递从父页面所需的值查询字符串价值你不需要在弹出的页面中的js函数。查询字符串值,您可以访问它的子页面的页面加载事件,并直接分配给它的文本框。

Or another possible solution would be to directly pass the required value from the parent page as a querystring value and you don't need the js function in the popup page. The querystring value you can access it in child pages's page load event and assign it directly to the textbox.

你的父母JS

   function NewCustOpn() {
        var ddlvalue = document.getElementById("<%=DropDownList1.ClientID%>").value;
        var popup = window.open("Popup.aspx?dropdownval=" + ddlvalue, "Popup", "toolbar=no,scrollbars=no,location=no,statusbar=no,menubar=no,resizable=0,width=520,height=350,left = 250,top = 50");
    }

并从你的孩子页面的code后面

 protected void Page_Load(object sender, EventArgs e)
 {
     if (!string.IsNullOrEmpty(Request.QueryString["dropdownval"])) {
         TextBox1.Text = Request.QueryString["dropdownval"];
     }
 }

这篇关于如何使用JavaScript来传递从父asp.net的DropDownList值文本框在弹出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆