How to use single Dialog Box for several multiline textboxes on a WebForm?

I have a form that contains several multiline textbox controls. Due to space considerations, I kept the textboxes 180px width and 40px height. I provided a small button (with caption ‘…’ suggesting, it opens a dialog window). I created a dialogbox.aspx page
that contains One big multiline textbox and two buttons, ‘Ok’ and ‘Cancel’. To host the dialog box, I am using a DialogBoxHost.aspx which contains only a frames and points to dialogbox.aspx. (Thanks to Bipin Joshi, for this technique) For
our example let’s name them ‘Desc’ and ‘Comment’. To edit the Desc box, when I click on the ‘…’ button, the text that is already there in the Desc box should be passed to the dialogbox. I attached the following javascript for that button. btnDesc.Attributes.Add("onClick",
"ShowDialog(‘" + Server.UrlEncode(txtDesc.Text) +"’ ,’txtDesc’);"); <script> function ShowDialog(TextData ,ctrlID) { var retval=""; retval=window.showModalDialog("edmDialogHost.aspx?TextData=" + TextData, window,’status:no;dialogWidth:400px;dialogHeight:350px;dialogHide:true;help:no;scroll:no’);
if(retval!="" && retval!=null){ document.getElementById(ctrlID).value=retval; } } </script> The control now goes to the DialogBoxHost.aspx which has the following html. " frameborder="no"> see here, I am trying pass the data through querystring and when
we come to the DialogBox.aspx, this is what I am trying to do. if (Request.QueryString["TextData"] != null) txtNotePad.Text = Server.UrlDecode(Request.QueryString["TextData"].ToString()); //This is always null???? btnOk.Attributes.Add("onclick", "window.returnValue
= document.getElementById(‘txtNotePad’).value; window.close();"); btnCancel.Attributes.Add("onclick", "window.close();"); The Ok and Cancel buttons are fine. My problem is, Request.QueryString["TextData"] in DialogBoxHost.aspx (the one with frames) has correct
value, but it is always null in DialogBox.aspx. I used session variables. It works fine if I have only one such box, since I have several boxes which refer to the same DialogBox.aspx, I cannot know which value to pass, in our example, did I click Desc box
or Comment box? I hope I am clear. Please help. Thanks
btnDesc.Attributes.Add("onClick", "ShowDialog(‘" + Server.UrlEncode(txtDesc.Text) +"’ ,’txtDesc’);");

The problem is with this code you have on click event of the button. Server.UrlEncode is .net server side code.

You should be using encodeuricomponent method in JavaScript see below

Pass it in your text box value

Leave a Reply