Parent page (page_load):
string script = @“
function setSearchText(theText)
{
textBox=document.getElementById({0}).value=theText;
}
“;
this.ClientScript.RegisterClientScriptBlock(this.GetType(), “setSearchText”, string.Format(script,EncodeJsString(txtItemSearch.ClientID)),true);
Child page (the usual place..):
string script = @” if (window.opener && window.opener.setSearchText)
{
window.opener.setSearchText({0});
}
window.close();
“;
this.ClientScript.RegisterClientScriptBlock(this.GetType(), “setSearchText”, string.Format(script,EncodeJsString(row.Cells[0].Text)),true);
public static string EncodeJsString(string s)
{
StringBuilder sb = new StringBuilder();
sb.Append(“\”");
foreach (char c in s)
{
switch (c)
{
case ‘\”‘:
sb.Append(“\\\”");
break;
case ‘\\’:
sb.Append(“\\\\”);
break;
case ‘\b’:
sb.Append(“\\b”);
break;
case ‘\f’:
sb.Append(“\\f”);
break;
case ‘\n’:
sb.Append(“\\n”);
break;
case ‘\r’:
sb.Append(“\\r”);
break;
case ‘\t’:
sb.Append(“\\t”);
break;
default:
int i = (int)c;
if (i < 32 || i > 127)
{
sb.AppendFormat(“\\u{0:X04}”, i);
}
else
{
sb.Append(c);
}
break;
}
}
sb.Append(“\”");
return sb.ToString();
}