从Dojo打开ASPX表单

时间:2014-01-03 15:29:00

标签: javascript asp.net dojo

我想用Dojo打开我的aspx表单?可能吗?请指导我。我的代码在

之下
OpenMyForm: function() {
          dojo.xhrGet({
                      url: "WebForm2.aspx",
                      handleAs: 'json'
                     });
                   }

当我运行此代码时,没有错误,但也没有打开表单。

我的aspx是

<body>
  <div id="frm">
    <form id="form1" runat="server">
    <div id="clist">

    <asp:Button ID="Button1" runat="server"    onclick="Button1_Click" Text="Button" />

    </div>
    </form>
   </div>
</body>

1 个答案:

答案 0 :(得分:1)

尝试将其更改为以下内容:

OpenMyForm: function() {
  alert("Will make a request now!");
  dojo.xhrGet({
      url: "WebForm2.aspx",
      handleAs: 'text',
      load: function(text) { alert("Success! " + text); },
      error: function(error) { alert("An error occurred! " + error); }
  });
  alert("Made the request, now waiting for the response!");
}

这可以让你知道事情的发展方向。

load功能是关键。它在请求成功时被调用,因此您可以在此告诉Javascript如何处理服务器生成的“表单”。 如果上述内容似乎有效,您可以尝试添加:

假设上述工作(根据您的评论确实如此),您可以尝试将表单实际放置在页面上。替换此行:

load: function(text) { alert("Success! " + text); },

用这个:

load: function(text) { document.getElementById("some_div").innerHTML = text; },

确保您的网页上有一个id为“some_div”的div(或相应更改)。现在,脚本不是成功对话,而是将文本(希望是您的aspx表单)放在页面上。

如果要在对话框中显示新表单,可以用这些行替换加载行:

load: function(text) {
    var dialog = dijit.byId("some_dialog");
    dialog.set("content", text);
    dialog.show();
},

请注意,它需要先创建一个dijit.Dialog。例如,在脚本的其他位置,您将拥有类似的内容:

dojo.require("dijit.Dialog");
dojo.ready(function() {
    window.myDialog = new dijit.Dialog({
        id: "some_dialog",
        title: "My dialog!"
});

确保你已经包含了dijit.css(参见dijit.Dialog示例:http://dojotoolkit.org/reference-guide/1.6/dijit/Dialog.html)。