Reputation: 703
I am creating a website using asp.net. I am calling the modal dialog if the user click the login link.
This is my script for showModalDialog.
<li><a onclick="popup()"href="#">LOGIN</a></li>
<script type="text/javascript">
function popup() {
var style = 'dialogWidth:350px;dialogHeight:100px;dialogleft:200px;dialogtop:200px;status:no;help:no;';
var respond = window.showModalDialog("login.aspx", this, '', style);
}
The login page consist of textbox for username and password and button for login button. After checking the username and password in the database my problem is how to pass the value from the popup page to parent page (boolean and string datatype) using code behind (.cs). If it is possible after passing the value to the parent page it will load the membership page if the boolean = true.
Thanks in advance.
Upvotes: 3
Views: 4861
Reputation: 6277
Could you expose the boolean in the code behind as a property which you can then write directly into the page i.e.
window.returnValue = '<%=MyPublicProperty%>;'
When the page is rendered then the property will just be any other javascript reference i.e.
window.returnValue = 'thePropertyValue';
So the modal dialog return type will reflect what was in the code behind
Another variation would be to use the ClientScript
object to write the code behind variable into the markup so it is available to the client to return from the modal dialog
ClientScript.RegisterClientScriptBlock(this.GetType(), "example",
string.Format("var codeBehindProperty = '{0}';", MyPublicProperty), true);
Hope that makes sense
EDIT
And to retrieve that information it should be the return value from the showModalDialog call. So in your example
var respond = window.showModalDialog("login.aspx", this, '', style);
The variable respond
will contain the codeBehindProperty
. If you were to step through the code then execution would pause at showModalDialog
while the modal was opened. When it closes then the execution continues and the return value is then available in the parent page.
Upvotes: 1