1

在我的 Vb .net 代码隐藏(Visual Studio 2005)中,在单击事件触发的方法中:

hdnUrl 和 hdnParameters 是 hiddenFields

Protected Sub btnExample_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExample.Click
.
.
.
hdnUrl.Value = "Mypage.aspx?i=" & SomeCveDefinedInCodeBehind.Tostring & "&u=" & OtherCveDefinedInCodeBehind.Tostring
hdnParameters.value = "resizable: no; scroll: no; center: yes; dialogHeight: 525px; dialogWidth:750px; status: no;"

ScriptManager.RegisterClientScriptBlock(Page, Page.GetType, DateTime.Now.ToString, "<script type='text/javascript'> ShowWindow(); </script>", False)

.
.
.

在我的页面中:

<asp:Content ID="Content3" ContentPlaceHolderID="cph3" runat="Server">
.
.
.
<asp:HiddenField ID="hdnUrl" runat="server" Value="" />
<asp:HiddenField ID="hdnParameters" runat="server" Value="" />
<asp:HiddenField ID="hdnResult" runat="server" Value="" />

<script language="javascript" type="text/javascript">

    function ShowWindow()
    {

      alert('i am here');

      var url = document.getElementById('<%= hdnUrl.ClientID %>').value;
      var Parameters = document.getElementById('<%= hdnParameters.ClientID %>').value;

      //For test:      
      alert(url);  //------ i need to get here: "My page.aspx?...", but i always get: ""
      alert(parameters); // i need to get here my parameters,   but i always get: ""
      .
      .
      .

      var dialogWin = window.showModalDialog(url, "some text", parameters);  //showModalDialog window, will return a data that i need in CodeBehind 
      document.getElementById('<%= hdnResult.ClientID %>').value=dialogWin.result;
      //Then i could manage the result, in code-behind      
    }

</script>

</asp:Content>

仅当我在隐藏字段定义中设置:

<asp:HiddenField ID="hdnUrl" runat="server" Value="My text" />

我可以在 javascript 警报中获取此文本,但我需要在代码隐藏中定义文本

感谢您的帮助和建议。是否有另一种方法可以将 url 和参数传递给 window.showModalDialog ???或在code.behind中获取window.showModalDialog结果的另一种方式???

4

1 回答 1

0

观察参数变量的大小写。也尝试使用 RegisterStartupScript 而不是 RegisterClientScriptBlock。不同之处在于前者会将您的 javascript 放在页面底部,而后者会将其放在顶部。这将导致脚本在它完全加载的文档之前运行。

ScriptManager.RegisterStartupScript(Page, Page.GetType, DateTime.Now.ToString, "<script type='text/javascript'> ShowWindow(); </script>", False)
于 2013-07-25T01:36:55.050 回答