首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

可否一次性赋值完成?(此 有关问题没解决,没心情过年)

2014-04-29 
可否一次性赋值完成?(此 问题没解决,没心情过年)问题是这样子,Insus.NET是想完成iframe内的form选择选项,

可否一次性赋值完成?(此 问题没解决,没心情过年)
问题是这样子,Insus.NET是想完成iframe内的form选择选项,填写完文本框之后提交数据。但是它需要点击两次才能填充完成。要怎样才能一次性选择和填充完成呢?
可以看到下面的操作:
可否一次性赋值完成?(此 有关问题没解决,没心情过年)


希望网友们给Insus.NET指点一二,感激不尽!如果你觉得问题点分不够多,Insus.NET可以再加(可惜最多只能为300点)。

下面提供关键代码,页面代码:


  <script type="text/javascript">      

        var localUrl = 'Imitation.aspx';       
        $('<iframe />', {
            id: 'frame1',
            name: 'frame1',
            //style: 'display:none',           
            src: localUrl,
            frameborder: 1,
            scrolling: 'no',
            width: '100%',
            load: function () {
                var oIframe = document.getElementById('frame1');

                oIframe.style.height = $.FrameDocument(oIframe).body.scrollHeight + 'px';

                if ($.FrameDocument(oIframe).location.href != localUrl)
                    window.location.href = "Default.aspx";
            }
        }).appendTo('body');

        $(document).ready(function () {
            $('#btn').click(function () {
                $.ajax({
                    async: false,
                    type: "GET",
                    url: 'BarcodeData.aspx',
                    dataType: "jsonp",
                    crossDomain: true,
                    cache: false,
                    jsonp: "callback",
                    error: function (jqXHR, textStatus, errorThrown) {
                        alert(jqXHR + '\n\r Error Message: ' + textStatus + '\n\r HTTP Error: ' + errorThrown);
                    },
                    success: function (data) {
                        data = $.parseJSON(data);
                        $.each(data, function (index, item) {
                            var $iframe = $('iframe').contents();

                            $iframe.find('#rdblstLocationCategory_2').attr("checked", true).triggerHandler('click');
                            $iframe.find('#chkNeedAutoSign').attr("checked", true);
                            $iframe.find('#chkWillGenerateNewMateriel').attr("checked", true).triggerHandler('click');

                            $iframe.find('#txtOutPutItemCode').val(item.ItemCode);



                            $iframe.find('#txtTraveler1').val(item.Number);
                            $iframe.find('#lstToLocation').val(item.ToLocal);

                            // $iframe.find('#btnOK').click();

                            // $iframe.find('#btn').click();
                        });
                    }
                });
            });
        });

        $.extend({
            FrameDocument: function (obj) {
                var oDoc = (obj.contentWindow || obj.contentDocument);
                if (oDoc.document)
                    oDoc = oDoc.document;
                return oDoc;
            }
        });
    </script>

    <div>
        <p>
            <input type="button" id="btn" name="btn" value="提交" />
        </p>
    </div>




另外ifrmae包含的Imitation.aspx:

 <p>
                <asp:RadioButtonList ID="rdblstLocationCategory" runat="server" AutoPostBack="True" RepeatLayout="Flow" RepeatDirection="Horizontal" OnSelectedIndexChanged="rdblstLocationCategory_SelectedIndexChanged">
                    <asp:ListItem Value="Cutter" Text="Cutter"></asp:ListItem>
                    <asp:ListItem Value="FQA" Text="FQA"></asp:ListItem>
                    <asp:ListItem Value="WIP" Text="WIP"></asp:ListItem>
                </asp:RadioButtonList>&nbsp;&nbsp;
                <asp:CheckBox ID="chkNeedAutoSign" runat="server" Text="自动签收"></asp:CheckBox>&nbsp;&nbsp;
                <asp:CheckBox ID="chkWillGenerateNewMateriel" runat="server" AutoPostBack="True" Text="产出新物料" OnCheckedChanged="chkWillGenerateNewMateriel_CheckedChanged"></asp:CheckBox>&nbsp;&nbsp;
                <asp:CheckBox ID="chkWillIntegrateTraveler" runat="server" AutoPostBack="True" Text="整合跟踪批"></asp:CheckBox>
            </p>
            <p>
                批号:<asp:TextBox ID="txtTraveler1" runat="server"></asp:TextBox>
            </p>
            <p>
                至场所:<asp:DropDownList ID="lstToLocation" runat="server">
                </asp:DropDownList>
            </p>
            <p>
                新编号:<asp:TextBox ID="txtOutPutItemCode" runat="server" Visible="false"></asp:TextBox>
            </p>
            <p>


                <asp:Button ID="btn" runat="server" Text="提交保存" OnClick="btn_Click" />
            </p>



ifrmae包含的Imitation.aspx.cs:

   protected void rdblstLocationCategory_SelectedIndexChanged(object sender, EventArgs e)
    {
      var rbl   = (RadioButtonList)sender;
      if (rbl.SelectedValue == "WIP")
      {
          DataTable table = new DataTable();
          table.Columns.Add("key", typeof(string));
          table.Columns.Add("value", typeof(string));

          table.Rows.Add("120-RM ST(CR1)", "120-RM ST(CR1)");
          table.Rows.Add("121-RM ST(CR2)", "121-RM ST(CR2)");
          table.Rows.Add("125-CW1", "125-CW1");
          table.Rows.Add("130-Sub Con", "130-Sub Con");
          table.Rows.Add("135-CW3", "135-CW3");
          table.Rows.Add("140-SFG ST(CR3)", "140-SFG ST(CR3)");         

          this.lstToLocation.DataSource = table;
          this.lstToLocation.DataTextField = "key";
          this.lstToLocation.DataValueField = "value";
          this.lstToLocation.DataBind();
      }
      else
      {
          DataTable dt = new DataTable();
          this.lstToLocation.DataSource = dt;  
        
          this.lstToLocation.DataBind();
      }
    }
    protected void chkWillGenerateNewMateriel_CheckedChanged(object sender, EventArgs e)
    {
       var chk = (CheckBox)sender;

       this.txtOutPutItemCode.Visible = chk.Checked ? true : false;
    }



最后是BarcodeData.aspx.cs:

   protected void Page_Load(object sender, EventArgs e)
    {
        string jsonString = DataTableToJsonString(BcTable());

        Page.Controls.Clear();
        string callback = Request["callback"];
        Response.Write(callback + "('" + jsonString + "')");
    }

    private string DataTableToJsonString(DataTable dt)
    {
        System.Web.Script.Serialization.JavaScriptSerializer jss = new System.Web.Script.Serialization.JavaScriptSerializer();
        List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>();
        Dictionary<string, object> row;

        foreach (DataRow dr in dt.Rows)
        {
            row = new Dictionary<string, object>();
            foreach (DataColumn dc in dt.Columns)
            {
                row.Add(dc.ColumnName, dr[dc]);
            }
            rows.Add(row);
        }
        return jss.Serialize(rows);
    }


    private DataTable BcTable()
    {
        DataTable table = new DataTable();       
        table.Columns.Add("Number", typeof(string));          


        table.Columns.Add("ToLocal", typeof(string));
        table.Columns.Add("IsGenerateNewItem", typeof(bool));
        table.Columns.Add("ItemCode", typeof(string));

        table.Rows.Add("T1234", "125-CW1", true, "F00-238-0001");       
       
        return table;
    }

热点排行