Text box content rendering in a new window using javascript - c#

I have a asp.net textbox(textarea which is in a repeater have single texarea for each record which are read only) I have button (open in new window) when i click on it the content of the text area needs to be rendered in a new window using javascript .
similar to experts exchange.

Sorry I misread the question the first time.
Here is a javascript solution:
function DisplayTextFromRepeater()
{
var text = '';
var repeater = document.getElementById('MyRepeater');
var inputs = repeater.getElementsById('input');
var txtId = 'MyTextBox' //ID of textbox in repeater template
for(var i = 0; i < inputs.length; i++)
{
if(inputs[i].type == 'text')
{
if(inputs[i].id.indexOf(txtId) != -1)
{
text = text + inputs[i].value;
}
}
}
OpenNewWindow(text);
}
function OpenNewWindow(message)
{
var OpenWindow = window.open("", "newwin", "height=250, width=250,toolbar=no,scrollbars=yes,menubar=no");
OpenWindow.document.write("<html>");
OpenWindow.document.write("<title>Title Goes Here</title>");
OpenWindow.document.write("<body>");
OpenWindow.document.write(message);
OpenWindow.document.write("</body>");
OpenWindow.document.write("</html>");
}

Related

How to handle the mouse wheel button event in ASP.NET?

I have a project which uses EXT.NET framework for the controls. I'm currently working on the behavior of closing the panel tabs such as Google Chrome and all the modern browsers does.
I couldn't find the answer to this. What is the ASCII value for the mouse scroll wheel button? How can I handle this event in C# ASP.NET?
working on Firefox, Explorer and Chrome:
$(document).ready(function() {
$(document).mousedown(function(e) {
closeTab(e);
});
});
function closeTab(e) {
if (!e) {
e = window.event;
e.which = e.keyCode;
}
if(e.which == 2){
var tbpPrincipal = <%= tbpPrincipal.ClientID %>;
var activeTab = null;
for (var i = 0; i < tbpPrincipal.items.length; i++) {
var currentTab = tbpPrincipal.items.items[i];
if (e.target.innerText == currentTab.title || e.target.textContent == currentTab.title) {
activeTab = currentTab;
break;
}
}
if (activeTab) {
var activeTabIndex = tbpPrincipal.items.findIndex('id', activeTab.id);
tbpPrincipal.remove(activeTabIndex);
}
}
return true;// to allow the browser to know that we handled it.
}

Generating Text box control from behind "C#"

i am kinda new to asp.net, and also my english not really good, anyway i hope you still can get my point. nah i have a question here, basically i trying to integrate my app with LinkedIn, so i am using REST API, when i click a button it redirect my page to request data from LinkedIn, it returned XML data, and it contain user's education data, the count of user's education data is uncertain, so i decided to generate text box control from behind ("C#"). i do this :
TextBox txt;
int i;
foreach (var element in person)
{
if ((element.Name == "first-name") || (element.Name == "last-name"))
{
tbName.Text = tbName.Text + " " + element.Value;
}
else if (element.Name == "skills")
{
i = 1;
foreach (var child in element.Elements())
{
if (child.Name == "skill")
{
txt = new TextBox();
txt.ID = "tbSkills" + i;
txt.Width = 200;
txt.Visible = true;
txt.ReadOnly = true;
txt.Text = child.Element("skill").Element("name").Value;
form1.FindControl("divMoreSkills").Controls.Add(txt);
i++;
}
}
}
else if (element.Name == "industry")
{
tbIndustry.Text = element.Value;
}
else if (element.Name == "educations")
{
i = 1;
foreach (var child in element.Elements())
{
if (child.Name == "education")
{
txt = new TextBox();
txt.ID = "tbEducations" + i;
txt.Width = 200;
txt.Visible = true;
txt.ReadOnly = true;
txt.Text = child.Element("school-name").Value;
form1.FindControl("divMoreEducations").Controls.Add(txt);
i++;
}
}
}
}
}
my question is, if i want to use text box i generated previously later, does C# will recognize it? because the control i generated did not have runat server property.
thank you.
if i want to use text box i generated previously later, does C# will
recognize it? because the control i generated did not have runat
server property.
You don't have to specify runat="server", since from the code behind you will be creating server side controls. runat="server" is used on the aspx pages to identify server side controls.
To find it, you need to make sure that these controls are available on the post back. you can find them like you are finding your div in form1. Use Page.FindControl
Yes it will.. You can use added control like
TextBox txt = (TextBox )Page.FindControl("tbSkills0");

How can I highlight a word within gridview

How can I highlight the text of a query in the gridview control?
if you want do this client side please follow this steps:
add jQuery reference to your page.add a text input calles txt_Search.
and then use this script:
$(document).ready(function () {
$('#txt_Search').keyup(function () {
searchTable($(this).val());
});
function searchTable(inputVal) {
var table = $('#GridView1');
table.find('tr').each(function (index, row) {
var allCells = $(row).find('td');
if (allCells.length > 0) {
var found = false;
allCells.each(
function (index, td) {
var regExp = new RegExp(inputVal, 'i');
if (regExp.test($(td).text())) {
found = true;
return false;
}});
if (found == true) $(row).show(); else $(row).hide();
}
});
}
});
var gv = document.getElementById("#GridView1");
for (var i = 0; i < gv.all.length; i++) {
var cellValue = grid.rows[i].cells[0].elements[0];
cellValuestyle.background = '#DD00DD';
}
search the text, dress them with a tag like <label>, and don't forget to add highlight style for the labels.

CheckBox inside ListView control using ASP.Net 3.5

When CheckBox is unchecked in a ListView i need to get a popup window?
I have make a JS function and just pass id of your list like as
OnClientClick="return GetSelectedCheckBoxInGrid('grdCustomer');"
function GetSelectedCheckBoxInGrid(obj)
{
var con = 'ctl00_ContentPlaceHolder1_' + obj
var Parent = document.getElementById(con);
var TargetChildControl = "chk";
if (Parent==null)
{
return false;
}
var items = Parent.getElementsByTagName("input");
for(var n = 0; n < items.length; ++n)
if(items[n].type == 'checkbox' &&
items[n].id.indexOf(TargetChildControl,0) >= 0 &&
items[n].checked == false)
alert('Hi');return false;)
}
I think this is that
Not too sure about this, but hypothetically, you could give each checkbox a class, eg chkbox, and then have some jquery code to handle a click event:
$('chkbox').click(function() {
alert("here is where you put your popup code");
});
You could use window.open here
$('chkbox').click(function() {
if (! $('#chkbox').is(':checked'))
{
window.open ("http://www.javascript-coder.com","mywindow","status=1");
}
});
or
$('chkbox').click(function() {
if(! $('#chkbox').attr('checked'))
{
window.open ("http://www.javascript-coder.com","mywindow","status=1");
}
});
How to check whether a checkbox is checked in jQuery?

Clear asp.net form at runtime

Whats the easiest way to clear an asp.net form at runtime using c#.
Thanks
Sp
I assume you want to clear input boxes, dropdowns etc. This can be done the following way in code to recursivly clear all data.
foreach( var control in this.Controls )
{
ClearControl( control );
}
and the recursive function
private void ClearControl( Control control )
{
var textbox = control as TextBox;
if (textbox != null)
textbox.Text = string.Empty;
var dropDownList = control as DropDownList;
if (dropDownList != null)
dropDownList.SelectedIndex = 0;
// handle any other control //
foreach( Control childControl in control.Controls )
{
ClearControl( childControl );
}
}
I have used the following JS/c# to clear the form.
c# to add the js call onload
Page.ClientScript.RegisterStartupScript(typeof(WebForm3), "ClearPage", "ClearForm();", true);
the JS to clear the form
function ClearForm() {
var AllControls = document.getElementById('ctl00_ContentPlaceHolder1_PnlAll')
var Inputs = AllControls.getElementsByTagName('input');
for (var y = 0; y < Inputs.length; y++) {
// define element type
type = Inputs[y].type
// alert before erasing form element
//alert('form='+x+' element='+y+' type='+type);
// switch on element type
switch (type) {
case "text":
case "textarea":
case "password":
//case "hidden":
Inputs[y].value = "";
break;
}
}
}

Categories