Passing Text of a text box in child form to a label in parent form

Hi Elite People !!

I have a parent form with a number of ASP Labels and Buttons. Each ASP Label has a ASP Button next to it. What I want to acheive is when you click the button, it should open a new window with a ASP multiline text box and a "save" button. User can enter the text in the text box and when they click the SAve button, the Text in the text box of the Child window should be displayed in the label on the parent form.

 I am successfully able to do this when I have a Text Box in the Parent form, but my requirement is to use Labels on the Parent Form. I am also using a Master page on the parent form.

And as I have multiple Labels on the Parent form, is there a way to acheive this with creating just one child window or I will have to create multiple child windows for each Label in the parent as text for each label is going to be different.

 How can I acheive this ??

 I would really appreciate the help.

 Thanks!

0
lost_floyd
9/10/2008 8:24:32 PM
asp.net.client-side 24353 articles. 1 followers. Follow

13 Replies
1028 Views

Similar Articles

[PageSpeed] 35

Hi,

One solution:

-Create a single popup form with a TextBox and a Save / Close button. e.g. "TextForm.aspx"
-Accept a query string parameter (or a POST argument) that specifies which field this form is operating on
-In your parent form (with Labels) script your buttons to load this window:

showModalDialog("TextForm.aspx?Field=AboutMe","textEditorWindow","toolbar=no,status=no,menubar=no,resizeable=no,scrollbars=no"); 

 in this example we will be using this to update a field called "AboutMe" you could also include a table param e.g. Table=UserProfile, etc. If security is a concen you may want to encode this data to stop scripting hacks.

-In TextForm.aspx write some code to write the value of the TextBox to the correct field / table when the Save button is pressed.
-If you do this with a postback then get the form to execute a block of script after the postback. If you do this with a call back chain the following script after the callback has completed.
-Write a script block for TextForm.aspx that calls a function in the parent (opening) window. I believe the handle can be obtained using window.opener from the child window but you'll have to look this up. After you have called the function close the popup with window.close();
-In the parent (Label) form write the script function that is to be called. This function will cause the parent form to update the label. You can either do this with a callback or you can just force the page to do a postback, it's up to you.

Cheers,

0
O11Y
9/11/2008 8:53:39 AM

Hi,

   Is it an Ajax Enabled WebSite?

0
J
9/11/2008 9:05:13 AM

Hi

In this scenario I think one Child window is enough and just you need to pass the Label control Id for which it is updating the text.

For ex:Parent Form should like this ...

<form id="form1" runat="server">

<div>

<asp:Label ID="Label1" runat="server" Text="Label" ></asp:Label>&nbsp;

<asp:Button ID="Button1" runat="server" Text="Open" OnClientClick="return OpenChildWindow('Label1');return false;" /> <br />

<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>&nbsp;

<asp:Button ID="Button2" runat="server" Text="Open" OnClientClick="return OpenChildWindow('Label2');return false;" /> <br />

<asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>&nbsp;

<asp:Button ID="Button3" runat="server" Text="Open" OnClientClick="return OpenChildWindow('Label3');return false;" /> <br />

<input type="hidden" runat="server" id="hidTxt1" />

</div>

</form>

function OpenChildWindow(sender)

{

var vUrl="Child.aspx?Id="+sender;

window.open(vUrl);

return false;

}

and Child Page

<form id="form1" runat="server" defaultfocus="txtChild">

<div>

<asp:TextBox ID="txtChild" runat="server" TextMode="MultiLine" Rows="3" ></asp:TextBox><br />

<asp:Button ID="btnSave" Text="Save" runat="server" OnClientClick="return CloseWindow();return false" />

</div>

</form>

function CloseWindow()

{

var sLabelID='<%=strId %>';

var sNewLabelText=null;

if(sLabelID!=null)

{

sNewLabelText=document.getElementById('txtChild').value;

window.opener.document.getElementById(sLabelID).innerHTML=sNewLabelText;

}

window.close();

return false;

}

Code Behind in Child page

public static string strId = "";
protected void Page_Load(object sender, EventArgs e)

{

if(!IsPostBack)

strId = (this.Request.QueryString["Id"] != null) ? (this.Request.QueryString["Id"].ToString()) : String.Empty;

}

Note:Here we are set the Label Text from client side ,so it does not maintain the view state i.e. In code behind this Label Text value may be null.

If you need this also ,better use some hidden fields and and assign those values to these hidden fields and access them

If I have misunderstood your problem ,Please letus know.

Regards,

Satish.

0
satish4asp
9/11/2008 9:58:03 AM

Thanks a Ton Satish.... You really made my day... your suggestion works like a champ. I have one more question though.

 In the multiline text box that I have on the child form, if a user writes the text in paragraphs (i.e. the user hits Enter to change the paragraph or to start a new line), is there is way to have the same effect back on the label on the parent form?? (i.e. the text in the label on the parent form should also display with the paragraphs)

Eagerly waiting for your response.

 

0
lost_floyd
9/12/2008 1:35:54 AM

You can use the <br> element in a Label control to create a line break.

NC...

 

0
NC01
9/12/2008 1:47:42 AM

Hi Satish

Well I spoke too early Sad while your suggested code works well when I am not using a Master Page. But it does not work on my website where I am using Master pages on the parent form.

in my website with the master page, it opens the child window just fine. but when I enter the text in the text box and click save, nothing happens. I don't even get any error. I am truly baffeled. 

and I am still struggling with keeping the paragraphs intact on the label on the parent form.

Any ideas ??

 

0
lost_floyd
9/12/2008 1:54:54 AM

Set the OnClientClick in the Page_Load handler of the CodeBehind instead of in the markup:

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

Button1.OnClientClick = string.Format("return OpenChildWindow('{0}'); return false;", Label1.ClientID);

For line breaks in the Label, use <br> tags. 

NC...

0
NC01
9/12/2008 2:06:47 AM

Thanks a Ton NC...

That took care of the issue. Can you please explain how I can use the <br> tags in the label. Where in the code can I replace the Carriage in the text box on the child form with a <br/> tag on the label on the parent form ??

I apologize if it is too silly to ask

0
lost_floyd
9/12/2008 2:35:17 AM

var sNewLabelText = document.getElementById('txtChild').value;
while ( true )
{
 var currentValue = sNewLabelText;

 if ( sNewLabelText.indexOf('\r\n') > 0 )
  sNewLabelText = sNewLabelText.replace('\r\n', '<br>');
 else
  sNewLabelText = sNewLabelText.replace('\n', '<br>');

 if ( sNewLabelText == currentValue )
  break;
}

I couldn't easily figure out a RegEx expression to remove either "\r\n" or "\n", so I came up with that loop to replace all with the <br> tag. Maybe someone else can.

NC...

0
NC01
9/12/2008 2:25:26 PM

Dear NC,

 You truly rock ! Both of your suggestions work like a charm

All of you guys are truly awesome !!

0
lost_floyd
9/13/2008 12:43:57 AM

Just remember that if the page containing the Label does a PostBack, all changes to the Label will be lost since client-side changes to a Label are not persisted in ViewState. To get around this, replace those Labels with:

<asp:TextBox id="labelTextBox" BorderColor="White" BorderStyle="None" BorderWidth="0" runat="server"></asp:TextBox>

<script type="text/javascript">
<!--
// We need to set the ReadOnly property here, as in version 2.0,
// setting it in the markup does not persist client-side changes.
window.onload = function ()
{
 document.getElementById('<%= labelTextBox.ClientID %>').readOnly = true;
}
// -->
</script>

NC...

 

0
NC01
9/13/2008 2:00:55 PM

thanks for your valuable suggestions NC,

I indeed got in to the trouble that you explained. I have changed the labels on my parent forms to text box, but now I can't replace the carriage return in the text box on the child form with a new line in the text box on the parent form.

Any ideas ?? I am in desparate need to get this working. 

 

0
lost_floyd
9/19/2008 2:39:05 AM

Change the element declaration in the parent page to:
<asp:TextBox id="labelTextBox" BorderColor="White" BorderStyle="None" BorderWidth="0" runat="server" TextMode="MultiLine"></asp:TextBox>

Add this JavaScript to the parent page:
<script type="text/javascript">
<!--
function windowOnLoad()
{
 document.getElementById('<%= labelTextBox.ClientID %>').readOnly = true;
 document.getElementById('<%= labelTextBox.ClientID %>').style.overflow = 'hidden';  // Removes the scrollbars
}
window.onload = windowOnLoad;
// -->
</script>

And in the child page remove the string replace, just:
window.opener.document.getElementById('<%= Request["ID"] %>').value = '1\r\n2\r\n';
 // document.getElementById('txtChild').value;

NC...

0
NC01
9/19/2008 2:16:33 PM
Reply:

Similar Artilces:

Postback on Parent Form from Child Form client side javascript
I have 2 different .aspx files that require the input of a stock code. The stock code field on each form is defined as follows:- <INPUT id="txtStockCode" type="text" maxLength="30" name="txtStockCode" runat="server"> Next to the field on each form I have a clickable image defined as follows:- <IMG id="imgLookupStockItem" onclick="window.open('../frmLookup.aspx?Object=StockCodes')" src="../images/binoc.ico" name="LookupStockItem"> So when the user clicks on the binoculars image f...

How to pass a text box value on parent form to a popup page?
I have a parent page called 'Parent1.aspx' that has a button and a text box. When the button is clicked, a popup window opens. I want to pass the value of the text box on 'Parent1.aspx' to the code-behind of the popup window page.  Can some one please help? Thankssun21170 Here is an article on doing this for a popup calendar: http://aspnet.4guysfromrolla.com/articles/030202-1.aspx FWIW: If you are actually trying to create a popup calendar control, this isn't the best solution because the popup window can be blocked by popup blockers. There are numerous DateTextBox with popup calenda...

How ot pass string value from popup window to parent form text box
Hi,I created two forms for sending user data In first form i placed send TO:,CC:  two textboxs adding mail ids for sending mail. Two links TO:,CC: for selecting mail id from popup window grid view and i placed a button insert checked items ( I created the form like Yahoo compose page there we  can click on TO: it open one popup window for selecting mail ids), Tell me  how to pass mailid string to main form TO:, CC text boxes.and close popup window. in that button click event.I wish you goodluck 1. Take a Button in your Parent Form. Give its style as dis...

Setting label text = textbox text on other form
How can I set the text of a label on a user control equal to whatever the user types into a textbox on a .aspx file? Is there any easy way of referencing the label in the .ascx file? Create a property in the user control public property Text { get { return label1.text } set { label1.text = value; } } the property changes the value. BrianBrian"Trust in the Lord and do what is good; dwell in the land and live securely. Take delight in the Lord, and He will give you your heart's desires" (Psalm 37: 3-4). Hi !! Is that code will make the label text as...

Passing Values to parent form from child form
Hi All, I have two aspx pages. I have a parent form and a child form. When I click the button 'Open' on my  parent form, I open the child form. I must ensure that the child dosen't loose its control. So I used ShowModalDialog to open the child window, where I select a value from the list box. I have to pass this value to the parent form. Is it possible to pass the selected value to the parent window from this child? Any suggestions Thanks in Advance   Regards SridharRegardsSridharPlease Mark the Posts as Answered if they solve your question :) Hi Srid...

Load Text box of one web form with selected list item of list box of another web form
one help please Problem is i have two web forms  1.  ForiegnkeyTest.aspx  2. foroginkeytable.aspx   step 1 1 ForiegnkeyTest.aspx one web form <head runat="server"><script language="javascript" type="text/javascript">   function popWin()   {         var confirmWin = null;      confirmWin = window.open('foroginkeytable.aspx','anycontent',   'width=455,height=435,status');   }  </script> &...

control text in a text box inside a Form view
I want to get text from a querystring into a text box that is prt of a form view. I have tried writing code in the page load that changes the text value inside that text box but i get the error that the texbox name is not in the current context. My question is how to call a textbox (or any other control) inside a form view? You can use the FormView's OnDataBound event to access the textbox on your formview: OnDataBound="FormView1_OnDataBound" Protected Sub FormView1_OnDataBound(ByVal sender As Object, ByVal e As EventArgs)        If FormView1.Curren...

How to clear all text boxes on the form using a function on form
I want to use the following to clear all th text boxes on the form, but it complains on the following line: cntl.text = "" it says text is not a member of cntl. Can you please correct the code. Private Sub Cleartextboxes() Dim cntl As Control For Each cntl In Me.Controls If TypeOf cntl Is TextBox Then cntl.Text = "" End If Next End Sub Thank you very much for the information. Hi, you would need to cast the control to a TextBox before you can access Text...

Passing label text to a different form
I want to add some text to a label based on what is in a label on a different web form. So there is form1 with label 1 form2 with label 2 Is there a way I can pass the text in label 1 and assign it to label2? I am loading the form2 by Response.Redirect("Form2.aspx") How can I do this? Response.Redirect("leads.aspx?YourParameterName=" & HttpUtility.HtmlEncode(Label1.Text))Pandora Tomorrow Response.Redirect("Form2.aspx?labeltext" + label1.Text); // in form2 string text = Request.Params["labeltext"]; label2.Text = text...

Enabling button after text changed on text box from form view control
I'm using form view to display some text box that contains user's personal info. There are "save" buttons for each text box which are disable as default. I want to enable them when text is changed on the the text box. I don't know how to write the the JavaScript function to do this task and i also don't know how to call the function from the the textbox control (onchange or ontextchange?). Here is the formview code: <asp:FormView ID="FormView1" runat="server" DataSourceID ="personalSQL"> <ItemTemplate > <ta...

How do I block a user from entering text in a text box if they type text in another text box?
I have two text boxes, and want the user to complete one or the other.  How can I "grey out" one text box if a user starts typing in the other textbox?  Never make important decisions on a Monday! You can use the OnTextChanged event of the textboxes and write Javascript for both textboxes to disable the other textbox when the user starts to type in something in one textbox. The only problem with that is that once the user starts to type in something in one text box the other textbox gets disabled and locks up, so now the user HAS TO compulsarily type what he wants in th...

Check if the text box "text" has changed (RePost from web forms forum)
Greetings! How can i know if the "text" inside of a text box has changed? For example, I currently have this: if (txtMU.TextChanged()) { } But this does not work. The other idea I had was to assign the existing value of the text box to a string and then when the user click the save button I can create a conditional statement to compare the original string with the new string. However, I would like something more effective as I have like 12 text boxes to compare. Thanks, EduardoThanks,Please Mark this post as answered if it was helpful. Here is the easiest way that I have ...

force post back when passing paramter in text box detail form
hi Seniors i am working on asp.net application i passed a paramter to other detail window (Form) now i want to force postback on that text box to show detail on that deatil formGajani  postabcking a window is pretty easy....YOu can use either javascript / .net codeAre you passing the value as query string along with the url of new window ?then its for sure (if the target is an aspx page), the page load will call and you get the details with the new passed parameter Do remember to mark this as Answer if this fix your problemThanks & RegardsBinuKumar S...

VB .net Web Form will not get contents of Text Box
I have created a web form with text boxes that are bound to a DataSet/DataView.  I have created button to navigate up and down the recordset.  That all works fine. I need to have the ability to edit/add text in any of the boxes and then when clicking "Save" button, it would build an UPDATE query to send to the database. When the Save button is clicked, I have coded to DIM a string var (strSQL) to use to build the SQL command.  For some reason, it will only get the text from a text box if the data was pulled the database.  If I add/edit data, then the SQL command will ha...

Web resources about - Passing Text of a text box in child form to a label in parent form - asp.net.client-side

Passing off - Wikipedia, the free encyclopedia
This article includes a list of references , related reading or external links , but its sources remain unclear because it lacks inline citations ...

Facebook Gets Passing Grade From Irish Agency Audit - AllFacebook
Facebook received its report card in the form of a detailed audit by the Office of the Irish Data Protection Commissioner, and its grades were ...

Whether passing the 9/11 Health Bill,... - Kirsten Gillibrand - Facebook
Whether passing the 9/11 Health Bill, repealing DADT, or my call to action for women, I have always urged New Yorkers to make their voices heard. ...

Thread: Buck-passing bullshit.
The Repubs are tempting fate, trying to allocate blame for Obama's loss in November. Obviously it's a little presumptuous. If Romney wins, it's ...

Scripting News: People are asking about the history of RSS today because of Aaron's passing.
People are asking about the history of RSS today because of Aaron's passing. In April 2004 I put together a timeline of the various specs that ...

AfroCat ◆ Cute and free pet game ◆ Perfect for passing the time! on the App Store
Read reviews, compare customer ratings, see screenshots, and learn more about AfroCat ◆ Cute and free pet game ◆ Perfect for passing the time!. ...

walmart donated a palette of water. everyone was great about passing the bottles back
Explore pinguino's photos on Flickr. pinguino has uploaded 16442 photos to Flickr.

Astronauts Mark Leonard Nimoy’s Passing - YouTube
NASA Astronaut Mike Fincke and ESA European Space Agency Astronaut Luca Parmitano reflect on the inspiration that actor Leonard Nimoy’s character ...

UAE remembers Zayed 10 years after his passing
Several activities will be taking place on Ramadan 19th marking the 10th anniversary of Sheikh Zayed’s passing.

Should IVF be used to avoid passing on mutations?
Should IVF be used to avoid passing on mutations?

Resources last updated: 1/2/2016 4:19:11 PM