473,395 Members | 2,796 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,395 software developers and data experts.

Dynamically Setting Runat = Server on ButtonField?

Hi.

How do I add the runat=server attribute on a buttonfield link
dynamically?

thanks!

Oct 24 '07 #1
3 3511
It would be easier if it was already a server side control but then it would
be not necessary as it would be already a server side control ;-)

More seriously why can't you set this attribute once for all ? Just use the
runat="server" attribute? It doesn't mean you have actually to do something
with it. Use it or not as will.It should arm having this if this is not
needed.

You may want to explain what you are trying to do as you seems to have an
unusual scenario (this is just a guess but if you render directly HTML
markup, you could also create a server control dynamically instead and let
the server control render the HTML markup rather than creating "by hand" the
markup that you would like to turn into an HTML server control).

--
Patrice
"pbd22" <du*****@gmail.coma écrit dans le message de news:
11**********************@i13g2000prf.googlegroups. com...
Hi.

How do I add the runat=server attribute on a buttonfield link
dynamically?

thanks!

Oct 24 '07 #2
On Oct 24, 1:01 pm, "Patrice" <http://www.chez.com/scribe/wrote:
It would be easier if it was already a server side control but then it would
be not necessary as it would be already a server side control ;-)

More seriously why can't you set this attribute once for all ? Just use the
runat="server" attribute? It doesn't mean you have actually to do something
with it. Use it or not as will.It should arm having this if this is not
needed.

You may want to explain what you are trying to do as you seems to have an
unusual scenario (this is just a guess but if you render directly HTML
markup, you could also create a server control dynamically instead and let
the server control render the HTML markup rather than creating "by hand" the
markup that you would like to turn into an HTML server control).

--
Patrice

"pbd22" <dush...@gmail.coma écrit dans le message de news:
1193244512.527399.198...@i13g2000prf.googlegroups. com...
Hi.
How do I add the runat=server attribute on a buttonfield link
dynamically?
thanks!
all I am trying to do is add an ID tag and an onclick event to the
anchor tags generated by the server.
I am getting in a bit of tailspin.

the tags are generated in a for loop like this:

foreach (DataColumn col in dt.Columns)
{

ButtonField bnfield = new ButtonField();

////Initalize the DataField value.
bnfield.DataTextField =
col.ColumnName;

// Center it
bnfield.ItemStyle.HorizontalAlign =
HorizontalAlign.Center;

//Initialize the HeaderText field
value.
bnfield.HeaderText = col.ColumnName;

bnfield.ButtonType = ButtonType.Link;

bnfield.
////Add the newly created bound field
to the GridView.
vGridView.Columns.Add(bnfield);
Can you please "show me" how I could add an ID and Onclick attribute
to these tags?

Thanks.

Oct 24 '07 #3
Ah ok. To sort if off, it has nothing to do with the runat tag. A server
side control is just a control that is used server side (and if it comes
from aspx markup, it has a runat=server attributes so that ASP.NET knows it
should be instantiated server side. If instanciation is done in server side
code, this is by definition a server side control).

Now :

1) Keep in mind that what you define here is just a column so it doesn't
have an id as each control in this column will have its own id

2) IMO your best bet is to handle this in the RowDataBound event. In this
even the e.row pproerty gives you the current cells. You can then address
these cells. They'll contain a LinkButton object. You can then use its
methods to, get whatever you want.

Code could be similar to (VB.NET) :

For i As Integer = 0 To e.Row.Cells.Count - 1
For j As Integer = 0 To e.Row.Cells(i).Controls.Count - 1
If TypeOf e.Row.Cells(i).Controls(j) Is LinkButton Then
Dim lb As LinkButton = CType(e.Row.Cells(i).Controls(j),
LinkButton)
lb.Attributes.Add("onclick", "alert('My ID is " &
lb.ClientID & "');")
End If
Next
Next

Basically it browse all cells and all controls and if a control is a link
button it then add the onclick attributes.

--
Patrice
"pbd22" <du*****@gmail.coma écrit dans le message de news:
11**********************@k35g2000prh.googlegroups. com...
On Oct 24, 1:01 pm, "Patrice" <http://www.chez.com/scribe/wrote:
It would be easier if it was already a server side control but then it
would
be not necessary as it would be already a server side control ;-)

More seriously why can't you set this attribute once for all ? Just use
the
runat="server" attribute? It doesn't mean you have actually to do
something
with it. Use it or not as will.It should arm having this if this is not
needed.

You may want to explain what you are trying to do as you seems to have an
unusual scenario (this is just a guess but if you render directly HTML
markup, you could also create a server control dynamically instead and let
the server control render the HTML markup rather than creating "by hand"
the
markup that you would like to turn into an HTML server control).

--
Patrice

"pbd22" <dush...@gmail.coma écrit dans le message de news:
1193244512.527399.198...@i13g2000prf.googlegroups. com...
Hi.
How do I add the runat=server attribute on a buttonfield link
dynamically?
thanks!
all I am trying to do is add an ID tag and an onclick event to the
anchor tags generated by the server.
I am getting in a bit of tailspin.

the tags are generated in a for loop like this:

foreach (DataColumn col in dt.Columns)
{

ButtonField bnfield = new ButtonField();

////Initalize the DataField value.
bnfield.DataTextField =
col.ColumnName;

// Center it
bnfield.ItemStyle.HorizontalAlign =
HorizontalAlign.Center;

//Initialize the HeaderText field
value.
bnfield.HeaderText = col.ColumnName;

bnfield.ButtonType = ButtonType.Link;

bnfield.
////Add the newly created bound field
to the GridView.
vGridView.Columns.Add(bnfield);
Can you please "show me" how I could add an ID and Onclick attribute
to these tags?

Thanks.
Oct 24 '07 #4

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

Similar topics

0
by: LU | last post by:
I have code to dynamically add more text boxes when the user clicks the 'add another carrier' button. Problem is it creates the text boxes within the same table row as previously created boxes. ...
8
by: Donald Xie | last post by:
Hi, I noticed an interesting effect when working with controls that are dynamically loaded. For instance, on a web form with a PlaceHolder control named ImageHolder, I dynamically add an image...
0
by: Diane Yocom | last post by:
I'm very new to ASP.Net and probably jumped in a little over my head, but... I'm trying to create a user control that will control navigation through my site. It's sortof like Amazon.com, where...
1
by: Marcus | last post by:
I have a problem maybe one of you could help me with. I've created a data entry screen with lots of dynamically-created client-side controls. I create HTML texboxes client-side by assigning a...
2
by: Rob Roberts | last post by:
In a VS2005 ASP.NET project, I'm trying to find a way to change which css file is linked in based on the browser type. I'd like to use one css file for IE browsers, and a different one for all...
2
by: John Haycock | last post by:
Hi All I have a user control that uses a repeater to build a list of menu links: <itemtemplate> <li> <a href='news.aspx?newsID=<%# DataBinder.Eval(Container.DataItem,"newsID") %>'> <%#...
1
by: stimul8d | last post by:
okay; ASP. I have i listbox inside a user control which is dynamically created on page_init. I check for postback and only populate the datasource if it's false. regardless, i do this ...
4
by: pbd22 | last post by:
Hi. I am trying to add an "onclick" 'event to an anchor tag and this is proving harder than I imagined. The anchor HAS NO ID. And, there will be tons of them on the page. So, I cannot access...
7
by: RichB | last post by:
I am trying to get to grips with the asp.net ajaxcontrol toolkit, and am trying to add a tabbed control to the page. I have no problems within the aspx file, and can dynamically manipulate a...
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: 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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.