473,386 Members | 1,758 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How can you add Attributes to controls in template

ad
If TextBox1 is a control on a WebForm, we can add Javascript function by
adding attribute in the Page_Load event like:

protected void Page_Load(object sender, EventArgs e)
{
TextBox1.Attributes.Add("onclick", "return MyFunction('Tiger')");
}

But if the TextBox is in a template, How can we add the attributes with
codes?
Nov 19 '05 #1
1 849
You can add it in the ItemCreated/ItemDataBound event of the data-bound control

protected void My_ItemCreated(Object sender, DataGridItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
TextBox TextBox1 = (TextBox).e.Item.FindControl("TextBox1");
TextBox1.Attributes.Add("onclick", "return MyFunction('Tiger')");
}
}
Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Eric Anderson | last post by:
I'm not sure if this is the correct place to post this question so please feel free to redirect me if needed. I am writing a XSL transform document to perform a transform on an XML document. I...
3
by: Jyrki Keisala | last post by:
I have an XML file which looks like this: <command name="Options" phrase="Options"> <key value="z" extended="NONE" qual="L-CTRL" pause="100" repeat="1" duration="200"/> </command> <command...
3
by: Stephan Brunner | last post by:
Hi I have created two flavors of an XSLT stylesheet to transform all attributes of an XML document to elements: They both work as expected with MSXML and XMLSPY but throw an exception ...
3
by: Janaka | last post by:
I've seen and used some samples where you can set the onclick attrubute to a Button control to get it to do some javascript a la : btnUse.Attributes = "DoSomeJS()"; However when i try and get...
3
by: J'son | last post by:
Guys, I have created a custom class that derives from DataList so that I can add some custom client side functionality into each new item row (<td>). Heres the class in its simplest form: ...
3
by: Rob Roberts | last post by:
Is there any way to add attributes to GridView ButtonFields? I'm looking for a way to add event handlers to ButtonFields. With regular ASP.NET buttons, I can add event handlers by using the...
15
by: Arpan | last post by:
Consider the following code which retrieves data from a SQL Server 2005 DB table & displays it in a DataGrid: <script runat="server"> Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs)...
6
by: Jakub.Bednarczuk | last post by:
Hallo everybody I have the problem with getting attributes values and also attributes names. I am reading an xml file with DOM. Lets see an example: file I read <root> <Def></Def>...
5
by: mahesh.nimbalkar | last post by:
When I transform XML, XSLT automatically adds extra attributes to the node which are declared in DTD (default DTD attributes) . I just want XSLT not to add these extra default attributes from DTD....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.