Gaurang Says..

June 1, 2010

Wanna Add runat=”server” from javascript?

Filed under: Uncategorized — Gaurang @ 2:22 pm

Hi,

In Asp.net,any server side control,you will find runat=”server” ,right?

now suppose. you are adding html control dynamically from javascript and you have written code like this.

var count=0;

function AddTextBox()
{
//alert(’Function Called’);
var Td= document.getElementById(’ctl00_ContentPlaceHolder1_tdDegreeContainer’);
var newText = document.createElement(’Input’);
newText.type=”text”;
//Td.innerHTML=Td.innerHTML+”<br/>”;
var temp_name= “text”+count.toString();
newText.setAttribute(’id’,temp_name.toString());
var temp_value=”Degree”+count.toString();
newText.setAttribute(’value’,temp_value.toString());
//Creating Button for Add rows
//debugger;
//var Td= document.getElementById(’tdDegreeContaine’);
if(count<5)
{
Td.appendChild(newText);
}
else
{
alert(”Oops..!! You Can not Add more than 5″);
return;
}
document.getElementById(’bttRemoveButton’).disabled=false;
count++;
}

function AddTextBox()

{

var Td= document.getElementById(’ctl00_ContentPlaceHolder1_tdDegreeContainer’);

var newText = document.createElement(’Input’);

newText.type=”text”;

var temp_name= “text”+count.toString();

newText.setAttribute(’id’,temp_name.toString());

var temp_value=”Degree”+count.toString();

newText.setAttribute(’value’,temp_value.toString());

newText.setAttribute(’runat’,’server’);

Td.appendChild(newText);

}

count++;

}

i have written this code for adding “Educational Qualification(degree)” of the member.

Basically, this code will add html text box dynamically into the  ”td” control of the html/asp.net table.

try to complie above code… you will get following error.

“unformatted Server tag”

means,you can not add  runat=”server”  from javascript.

Then,What is the Alternative??

step1> Create  hidden html field(s) and add runat=”server” statically.

step2> Create one Sync() javascript function. which will assign the values of dynamically generated text box to the hidden field .

step3> B’coz of runat=”server” in hidden fileld. you can access it from code behind.


March 22, 2010

how to set width and word-wrap property of Literal or lable in asp.net

Filed under: Uncategorized — Gaurang @ 1:39 pm

Problem statement:by adding a text without space or new line in  the html container(Literal,label )will not set in that width and the whole text comes with scroll bar . that  we dont want.for more details.see the picture below.

Solution to this problem…

here is the code which i have used to solve this.

Literal l = new Literal();

l.Text = “<p style=\”word-wrap:break-word; width:530px; \”>” + datarow["scrap_content"].ToString() + “</p>”;

this.Controls.Add(l);

and finally the result will be look like this.
solution

special thanks to Rinkal sir.for finding this solution

December 22, 2009

Add Row and Column Dynamically in Table With C#

Filed under: Uncategorized — Gaurang @ 1:07 pm

Hi, to all
This is the first time i m going to post something with code…
Here is the code that will add the row and column dynamically in the table Control ….Assume that Table1 already has been there in page…

TableRow tr = new TableRow();

TableCell td1 = new TableCell();
TableCell td2 = new TableCell();

Label lb1 = new Label();
lb1.Text = “Lable inside the td1″;
td1.Controls.Add(lb1);

Label lb2 = new Label();

lb2.Text = “Lable inside the td2″;
td2.Controls.Add(lb2);

tr.Cells.Add(td1);
tr.Cells.Add(td2);

Table1.Rows.Add(tr);

here is some advance way, if you want to display data in  NxN format

public void  CreateRow()
{
TableRow trmain = new TableRow();
TableCell tdmain = new TableCell();
for (int i = 0; i <5; i++)
{
TableCell tdinside = new TableCell();
TableRow tr = new TableRow();
for (int j = 0; j < 5; j++)
{
TableCell td= new TableCell();
Label l = new Label();
l.Text = “Test Text “+”" +i.ToString()+j.ToString();
td.Controls.Add(l);
tr.Cells.Add(td);
}
tdinside.Controls.Add(tr);
tdmain.Controls.Add(tdinside);
}
trmain.Cells.Add(tdmain);
tbTest.Rows.Add(trmain);
}

public void  CreateRow()

{

TableRow trmain = new TableRow();

TableCell tdmain = new TableCell();

for (int i = 0; i <5; i++)

{

TableCell tdinside = new TableCell();

TableRow tr = new TableRow();

for (int j = 0; j < 5; j++)

{

TableCell td= new TableCell();

Label l = new Label();

l.Text = “Test Text “+”" +i.ToString()+j.ToString();

td.Controls.Add(l);

tr.Cells.Add(td);

}

tdinside.Controls.Add(tr);

tdmain.Controls.Add(tdinside);

}

trmain.Cells.Add(tdmain);

tbTest.Rows.Add(trmain);

}

it will display data in 5 Row x 5 column, for row update i’s limit and for columns j’s limit inside loops.

November 21, 2009

Have u ever think how “Orkut” Works….!!!!!

Filed under: Uncategorized — Gaurang @ 5:56 am

to use a orkut or any social networking site…its a very easy thing…but have u ever think how this kind of websites is working…???
i m developing a social networking website with “FamilyTree” structure….right now…i m facing lots of complication while developing this social networking site…
just for a example….
when we r sending a “Add as A friend” request…..what kind of code is executing behind the page….

this is just a example….there r so many things which is very easy to use…but difficult to develop….not exactly difficult but we have to be more careful while coding this things….

right now…i have completed “Friend List”,”Scrap book”,”Photo Gallery” and “Updates from Friend “….n still work is going on….every time i have to create controls dynamically and add into the container….n Click events n all that….

November 11, 2009

my latest work in Silverlight….

Filed under: Uncategorized — Gaurang @ 11:54 am

hi..

i have just finished my silverlight work of the current project..
basically i have to generate family tree structure in Silverlight3.0 …here is the snapshot

here..is the link to start with Silverlight…
http://www.learn-silverlight-tutorial.com/TheSilverlightFramework.cfm

Powered by WordPress