1
在我的VB.NET中代碼隱藏(Visual Studio 2005中),通過點擊觸發的事件的方法:更改HiddenField值的Javascript功能沒有改變,以便使用在showModalDialog
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的結果???
大鼠。我現在出於完全相同的原因在這裏。 – jp2code
從我發現,客戶端腳本不能在服務器端執行。 – jp2code