ASP.NET 2.0 Modal Dialog Window & Master Page

A

ABHIJIT B

Kindly help me in following

1.In my module, I am using two pages Parent(ManageUser) and Child()
page.

Parent window has textbox and button to open Child window
Child page opens as dialog window as you click on button in Parent
page using JavaScript showwmodaldialog().
Child window has textbox and button to return value back to parent
page.

I am new to ASP.NET 2.0.I tried doing following,

Aftrer entering any value in textbox of Child page and clicking Close
button value can be seen in Parent page textbox.

-----< I am doing this changes in CodeBehind files > -----

Now, I am trying to use Hidden Control using normal HTML

<input id="hdvRowID" type="hidden" runat="server" name ="hdvRowID"/>

hdvRowID.Value = "AB";

I am not able to access value in JavaScript code so it is giving error
while
taking value.

Books.book_id = document.getElementById('hdvRowID').value;

---------------------------------------------------------------------------------------------------------------------------

< Parent page code : >

if (!ClientScript.IsStartupScriptRegistered("ManageUser"))
{

ClientScript.RegisterStartupScript(this.GetType(), "ManageUser",
" <script language=javascript> " +
" function AddBook() {" +
" var returnVal = ''; " +
" returnVal =
window.showModalDialog('SearchUsers.htm', null,'status:no;dialogWidth:
500px; dialogHeight:500px;dialogHide:true;center:yes;help:no',window);
" +
"
document.getElementById('txtSLoginName').value = returnVal.book_id;
document.getElementById('txtSFirstName').value = returnVal.book_name;
" +
" return false; }" +
" </script>");
}
---------------------------------------------------------------------------------------------------------------------------
< Child page code : >

ClientScript.RegisterHiddenField("txthidLoginID1", "XYZ");

btnSUOK1.Attributes.Add("onclick", "return
ReturnBook()");

if (!
ClientScript.IsStartupScriptRegistered("SearchUsers"))
{
ClientScript.RegisterStartupScript(this.GetType(),
"SearchUsers",
" <script language=javascript> " +
" function Books() { " +
" var book_id = ''; var book_name = ''; }" +
" function ReturnBook() {" +
" var Books = new Object(); " +
" Books.book_id =
document.getElementById('textboxBookID').value; " +
" Books.book_name =
document.getElementById('textboxBookName').value; " +
" window.returnValue = Books; window.close(); }" +
//" return false; }" +
" </script>");
}

2. In our application we are using only one Master page having label
control

All pages uses Master page

<label id="lblHeader" class="ApplicationLabelStyle" style="font-
weight:normal" >DataChecker</label>

<asp:contentplaceholder id="ContentPlaceHolder1"
runat="server">
</asp:contentplaceholder>

I am trying to change Master page label lblHeader text to Manage User
using following code,I am getting error.

A.

Label lblMasterHeader = (Label)Master.FindControl("lblHeader");
lblMasterHeader.Text = "DataChecker - Manage Users";

B.

Label lblMasterHeader =
(Label)Master.FindControl("ContentPlaceHolder1").FindControl("lblHeader");
lblMasterHeader.Text = "DataChecker - Manage Users";

C.

string selectedValue =
Request.Form[this.FindControl("ContentPlaceHolder1").FindControl("lblHeader").UniqueID];
lblMasterHeader.Text = "DataChecker - Manage Users";
 
B

bruce barker

try:

Books.book_id = document.getElementById('<%=hdvRowID.ClientID%>').value;

also you should move away from a modaldialog solution. this is an IE only
feature and may be droped as IE becomes more w3c compliant. most site uses a
floating div to do this feature. the ajaxtoolkit also has a solution.


-- bruce (sqlwork.com)


ABHIJIT B said:
Kindly help me in following

1.In my module, I am using two pages Parent(ManageUser) and Child()
page.

Parent window has textbox and button to open Child window
Child page opens as dialog window as you click on button in Parent
page using JavaScript showwmodaldialog().
Child window has textbox and button to return value back to parent
page.

I am new to ASP.NET 2.0.I tried doing following,

Aftrer entering any value in textbox of Child page and clicking Close
button value can be seen in Parent page textbox.

-----< I am doing this changes in CodeBehind files > -----

Now, I am trying to use Hidden Control using normal HTML

<input id="hdvRowID" type="hidden" runat="server" name ="hdvRowID"/>

hdvRowID.Value = "AB";

I am not able to access value in JavaScript code so it is giving error
while
taking value.

Books.book_id = document.getElementById('hdvRowID').value;

---------------------------------------------------------------------------------------------------------------------------

< Parent page code : >

if (!ClientScript.IsStartupScriptRegistered("ManageUser"))
{

ClientScript.RegisterStartupScript(this.GetType(), "ManageUser",
" <script language=javascript> " +
" function AddBook() {" +
" var returnVal = ''; " +
" returnVal =
window.showModalDialog('SearchUsers.htm', null,'status:no;dialogWidth:
500px; dialogHeight:500px;dialogHide:true;center:yes;help:no',window);
" +
"
document.getElementById('txtSLoginName').value = returnVal.book_id;
document.getElementById('txtSFirstName').value = returnVal.book_name;
" +
" return false; }" +
" </script>");
}
---------------------------------------------------------------------------------------------------------------------------
< Child page code : >

ClientScript.RegisterHiddenField("txthidLoginID1", "XYZ");

btnSUOK1.Attributes.Add("onclick", "return
ReturnBook()");

if (!
ClientScript.IsStartupScriptRegistered("SearchUsers"))
{
ClientScript.RegisterStartupScript(this.GetType(),
"SearchUsers",
" <script language=javascript> " +
" function Books() { " +
" var book_id = ''; var book_name = ''; }" +
" function ReturnBook() {" +
" var Books = new Object(); " +
" Books.book_id =
document.getElementById('textboxBookID').value; " +
" Books.book_name =
document.getElementById('textboxBookName').value; " +
" window.returnValue = Books; window.close(); }" +
//" return false; }" +
" </script>");
}

2. In our application we are using only one Master page having label
control

All pages uses Master page

<label id="lblHeader" class="ApplicationLabelStyle" style="font-
weight:normal" >DataChecker</label>

<asp:contentplaceholder id="ContentPlaceHolder1"
runat="server">
</asp:contentplaceholder>

I am trying to change Master page label lblHeader text to Manage User
using following code,I am getting error.

A.

Label lblMasterHeader = (Label)Master.FindControl("lblHeader");
lblMasterHeader.Text = "DataChecker - Manage Users";

B.

Label lblMasterHeader =
(Label)Master.FindControl("ContentPlaceHolder1").FindControl("lblHeader");
lblMasterHeader.Text = "DataChecker - Manage Users";

C.

string selectedValue =
Request.Form[this.FindControl("ContentPlaceHolder1").FindControl("lblHeader").UniqueID];
lblMasterHeader.Text = "DataChecker - Manage Users";
 
M

Mark Rae [MVP]

also you should move away from a modaldialog solution.
Definitely.

this is an IE only feature

IE and, curiously, Safari for Mac... :)
and may be droped as IE becomes more w3c compliant. most site uses a
floating div to do this feature. the ajaxtoolkit also has a solution.

Yes indeed - extremely simple to set up...
 
A

ABHIJIT B

Thanks Bruce.

This is client requirement.Can you let me know How can I change Label
text of Master page in Content page

Thanks in advance.

try:

Books.book_id = document.getElementById('<%=hdvRowID.ClientID%>').value;

also you should move away from a modaldialog solution. this is an IE only
feature and may be droped as IE becomes more w3c compliant. most site uses a
floating div to do this feature. the ajaxtoolkit also has a solution.

-- bruce (sqlwork.com)



ABHIJIT B said:
Kindly help me in following
1.In my module, I am using two pages Parent(ManageUser) and Child()
page.
Parentwindowhas textbox and button to open Childwindow
Child page opens asdialogwindowas you click on button in Parent
page using JavaScript showwmodaldialog().
Childwindowhas textbox and button to return value back to parent
page.
I am new to ASP.NET 2.0.I tried doing following,
Aftrer entering any value in textbox of Child page and clicking Close
button value can be seen in Parent page textbox.
-----< I am doing this changes in CodeBehind files > -----
Now, I am trying to use Hidden Control using normal HTML
<input id="hdvRowID" type="hidden" runat="server" name ="hdvRowID"/>
hdvRowID.Value = "AB";
I am not able to access value in JavaScript code so it is giving error
while
taking value.
Books.book_id = document.getElementById('hdvRowID').value;

< Parent page code : >
if (!ClientScript.IsStartupScriptRegistered("ManageUser"))
                    {
ClientScript.RegisterStartupScript(this.GetType(), "ManageUser",
                        " <script language=javascript> " +
                        " function AddBook() {" +
                        "  var returnVal = ''; " +
                        "  returnVal =
window.showModalDialog('SearchUsers.htm', null,'status:no;dialogWidth:
500px; dialogHeight:500px;dialogHide:true;center:yes;help:no',window);
" +
                        "
document.getElementById('txtSLoginName').value = returnVal.book_id;
document.getElementById('txtSFirstName').value = returnVal.book_name;
" +
                        " return false; }" +
                        " </script>");
                    }
---------------------------------------------------------------------------­------------------------------------------------
< Child page code : >
ClientScript.RegisterHiddenField("txthidLoginID1", "XYZ");
                btnSUOK1.Attributes.Add("onclick", "return
ReturnBook()");
                if (!
ClientScript.IsStartupScriptRegistered("SearchUsers"))
                {
                    ClientScript.RegisterStartupScript(this.GetType(),
"SearchUsers",
                    " <script language=javascript> " +
                    " function Books()  { " +
                    " var book_id = ''; var book_name = ''; }" +
                    " function ReturnBook() {" +
                    " var Books = new Object(); " +
                    " Books.book_id =
document.getElementById('textboxBookID').value; " +
                    " Books.book_name =
document.getElementById('textboxBookName').value; " +
                    "window.returnValue = Books;window.close(); }" +
                    //" return false; }" +
                    " </script>");
                }
2. In our application we are using only one Master page having label
control
All pages uses Master page
<label id="lblHeader" class="ApplicationLabelStyle" style="font-
weight:normal" >DataChecker</label>
<asp:contentplaceholder id="ContentPlaceHolder1"
runat="server">
</asp:contentplaceholder>
I am trying to change Master page label lblHeader text to Manage User
using following code,I am getting error.

Label lblMasterHeader = (Label)Master.FindControl("lblHeader");
lblMasterHeader.Text = "DataChecker - Manage Users";

Label lblMasterHeader =
(Label)Master.FindControl("ContentPlaceHolder1").FindControl("lblHeader");
lblMasterHeader.Text = "DataChecker - Manage Users";

string selectedValue =
Request.Form[this.FindControl("ContentPlaceHolder1").FindControl("lblHeader­").UniqueID];
lblMasterHeader.Text = "DataChecker - Manage Users";- Hide quoted text -

- Show quoted text -
 
M

Mark Rae [MVP]

Can you let me know how can I change Label
text of Master page in Content page

You would typically create a property on the MasterPage and set it from the
content page.

Alternatively, you might just be able to do:

((Label)Master.FindControl("MyLabel")).Text = "Hello";

depending on how your MasterPage is constructed, though I would personally
favour the property method...
 
A

ABHIJIT B

Thanks Mark

Can you suggest mistake I am making in below code,

-----------------------------------------------------------------------------------------------------------------------------------------
Master page code :

<%@ Master Language="C#" AutoEventWireup="true"
CodeFile="DC.master.cs" Inherits="MasterPage" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<link href="DCStyleSheet/DCStyles.css" type="text/css"
rel="stylesheet" />
</head>
<body>
<form id="DCMaster" runat="server">

<table cellpadding="0" cellspacing="0" width="100%" border="0">
<tr>
<td style="height: 67px">
<table id="main_header_table" cellpadding="0"
cellspacing="0" height="51px" width="100%"
border="0">
<tr>
<td class="HeaderTDStyle1"><img alt="DC
Site logo" src="DCImages/DC.gif"/></td>
<td class="HeaderTDStyle3"><label
id="lblHeader" class="ApplicationLabelStyle" style="font-
weight:normal" >DC Application</label></td>
</tr>
</table>
</td>
</tr>
</table>

<div>
<asp:contentplaceholder id="ContentPlaceHolder1" runat="server">

</asp:contentplaceholder>

<asp:Label ID="masterCopyrightLabel" runat="server"
CssClass="CopyrightLabelStyle"
Text="Copyright 2000-2008 Nielsen. All Rights
Reserved"></asp:Label>
</div>
</form>
</body>
</html>
------------------------------------------------------------------------
Content page code :

protected void Page_Load(object sender, EventArgs e)
{
try
{
if (!IsPostBack)
{
/********* Setting Label ********/

Label lblMasterHeader =
(Label)Master.FindControl("lblHeader");
lblMasterHeader.Text = "DC - Users";

//ContentPlaceHolder content;
//content =
(ContentPlaceHolder)Page.Master.FindControl("lblHeader");

//((Label)Master.FindControl("lblHeader")).Text =
"Hello";


------------------------------------------------------------------------
 
M

Mark Rae [MVP]

Thanks Mark
Can you suggest mistake I am making in below code,

I certainly can...
<label id="lblHeader" class="ApplicationLabelStyle"
style="font-weight:normal" >DC Application</label>

That's an HTMLControl, not a WebControl, so it won't run server-side. Change
it to an said:
Label lblMasterHeader = (Label)Master.FindControl("lblHeader");

That will only work if you change the <label> to an <asp:Label> - otherwise
it will be an HTMLGenericControl, so the cast won't work...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,571
Members
45,045
Latest member
DRCM

Latest Threads

Top