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

advanced question: making <asp:ButtonColumn> CausesValidation=False

Hi,

i stated that this is an advanced question because i have a post from few
days ago that i received answers to with suggestions that looked good but
did not work, so please if you post a reply make sure your suggestion
actually works.

like a <asp:button> control have a CausesValidation property that allows it
to POST a button command event to the server without causing the page to
make validation on form inputs, i need to get the same functionallity to an
<asp:button> culomn with a delete command.

i tried to use the OnItemCreated event of the datagrid, to add this
property, but perhaps becuase the button inside the grid is actually an
array of buttons, setting the property had no effect.

also tried to make an <TemplateItem> with the button inside, but again
setting the property had no effect and the form did passed the validation
check.

please advise, but don't just throw "why don't you try this", and as it did
last time, it did not work.

i'm gessing there must be a way (even use javascript or something) - to make
a command from the grid row without passing the form validation.
TIA, z.

Nov 18 '05 #1
4 1984
Hi z.f:

Perhaps you could post some code to look at. I've tried this with an
ItemTemplate like so:

<form id="Form1" method="post" runat="server">
<asp:DataGrid id="DataGrid1" runat="server"
AutoGenerateColumns="False">
<Columns>
<asp:BoundColumn DataField="au_id" HeaderText="au_id"/>
<asp:TemplateColumn HeaderText="test">
<ItemTemplate>
<asp:Button Runat="server" ID="button1"
CausesValidation="False" />
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
<asp:TextBox Runat="server" ID="textbox1" />
<asp:RequiredFieldValidator Runat="server"
ID="requiredFieldValidator"
ControlToValidate="textbox1"
ErrorMessage="You screwed up" />
<asp:Button Runat="server" ID="mainbutton" />
</form>

In this case pressing a button in the DataGrid does not cause
validation.

--
Scott
http://www.OdeToCode.com

On Thu, 24 Jun 2004 11:20:03 +0200, "z. f."
<zi**@info-scopeREMSPAM.co.il> wrote:
Hi,

i stated that this is an advanced question because i have a post from few
days ago that i received answers to with suggestions that looked good but
did not work, so please if you post a reply make sure your suggestion
actually works.

like a <asp:button> control have a CausesValidation property that allows it
to POST a button command event to the server without causing the page to
make validation on form inputs, i need to get the same functionallity to an
<asp:button> culomn with a delete command.

i tried to use the OnItemCreated event of the datagrid, to add this
property, but perhaps becuase the button inside the grid is actually an
array of buttons, setting the property had no effect.

also tried to make an <TemplateItem> with the button inside, but again
setting the property had no effect and the form did passed the validation
check.

please advise, but don't just throw "why don't you try this", and as it did
last time, it did not work.

i'm gessing there must be a way (even use javascript or something) - to make
a command from the grid row without passing the form validation.
TIA, z.


Nov 18 '05 #2
i'll check it up ,

for now i managed to do with overriding the Validate method of the page
object and only if i want to, i call
MyBase.Validate()

but i will try your code as soon as i'll make another grid with delete
buttons etc', that should not make validation of other operation that the
page can do.

question: the button inside the <asp:TemplateColumn HeaderText="test">, how
it "knows" which id it acts for, do i need to write code in the
OnItemCreated , or it can handle a grid command like delete?

thanx.

"Scott Allen" <bitmask@[nospam].fred.net> wrote in message
news:gj********************************@4ax.com...
Hi z.f:

Perhaps you could post some code to look at. I've tried this with an
ItemTemplate like so:

<form id="Form1" method="post" runat="server">
<asp:DataGrid id="DataGrid1" runat="server"
AutoGenerateColumns="False">
<Columns>
<asp:BoundColumn DataField="au_id" HeaderText="au_id"/>
<asp:TemplateColumn HeaderText="test">
<ItemTemplate>
<asp:Button Runat="server" ID="button1"
CausesValidation="False" />
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
<asp:TextBox Runat="server" ID="textbox1" />
<asp:RequiredFieldValidator Runat="server"
ID="requiredFieldValidator"
ControlToValidate="textbox1"
ErrorMessage="You screwed up" />
<asp:Button Runat="server" ID="mainbutton" />
</form>

In this case pressing a button in the DataGrid does not cause
validation.

--
Scott
http://www.OdeToCode.com

On Thu, 24 Jun 2004 11:20:03 +0200, "z. f."
<zi**@info-scopeREMSPAM.co.il> wrote:
Hi,

i stated that this is an advanced question because i have a post from few
days ago that i received answers to with suggestions that looked good but
did not work, so please if you post a reply make sure your suggestion
actually works.

like a <asp:button> control have a CausesValidation property that allows itto POST a button command event to the server without causing the page to
make validation on form inputs, i need to get the same functionallity to an<asp:button> culomn with a delete command.

i tried to use the OnItemCreated event of the datagrid, to add this
property, but perhaps becuase the button inside the grid is actually an
array of buttons, setting the property had no effect.

also tried to make an <TemplateItem> with the button inside, but again
setting the property had no effect and the form did passed the validation
check.

please advise, but don't just throw "why don't you try this", and as it didlast time, it did not work.

i'm gessing there must be a way (even use javascript or something) - to makea command from the grid row without passing the form validation.
TIA, z.

Nov 18 '05 #3
In this case it would be a little different than the grid delete
command. You can get to the DataGridItem by asking for the sender's
parent, like this:

protected void Button1_Click(object sender, System.EventArgs e)
{
Button btn = sender as Button;
// now btn.Parent is equivalent to
// e.Item in DataGrid_Delete command
}

You might also find this article that I wrote helpful:
Tips for locating controls with the FindControl method, including
finding controls in DataGrid rows, Repeaters, DataGrid headers, and
user controls:
http://odetocode.com/Articles/116.aspx

--
Scott

On Thu, 24 Jun 2004 17:22:28 +0200, "z. f."
<zi**@info-scopeREMSPAM.co.il> wrote:
i'll check it up ,

for now i managed to do with overriding the Validate method of the page
object and only if i want to, i call
MyBase.Validate()

but i will try your code as soon as i'll make another grid with delete
buttons etc', that should not make validation of other operation that the
page can do.

question: the button inside the <asp:TemplateColumn HeaderText="test">, how
it "knows" which id it acts for, do i need to write code in the
OnItemCreated , or it can handle a grid command like delete?


--
Scott
http://www.OdeToCode.com
Nov 18 '05 #4
The correct answer to the original question:

In OnItemCreated, retrieve the ButtonColumn object by its index in
e.Item.Cells. Then access the first control in its control collection. That
is the Button control. Finally set CausesValidation to false on that
control.

Suppose the buttonColumn was the second column. It uses an index of 1.
Here's code in C#:

Button vButton = (Button) e.Item.Cells[1].Controls[0];
vButton.CausesValidation = false;

--- Peter Blum
www.PeterBlum.com
Email: PL****@PeterBlum.com
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx

"z. f." <zi**@info-scopeREMSPAM.co.il> wrote in message
news:uy******************@TK2MSFTNGP12.phx.gbl...
i'll check it up ,

for now i managed to do with overriding the Validate method of the page
object and only if i want to, i call
MyBase.Validate()

but i will try your code as soon as i'll make another grid with delete
buttons etc', that should not make validation of other operation that the
page can do.

question: the button inside the <asp:TemplateColumn HeaderText="test">, how it "knows" which id it acts for, do i need to write code in the
OnItemCreated , or it can handle a grid command like delete?

thanx.

"Scott Allen" <bitmask@[nospam].fred.net> wrote in message
news:gj********************************@4ax.com...
Hi z.f:

Perhaps you could post some code to look at. I've tried this with an
ItemTemplate like so:

<form id="Form1" method="post" runat="server">
<asp:DataGrid id="DataGrid1" runat="server"
AutoGenerateColumns="False">
<Columns>
<asp:BoundColumn DataField="au_id" HeaderText="au_id"/>
<asp:TemplateColumn HeaderText="test">
<ItemTemplate>
<asp:Button Runat="server" ID="button1"
CausesValidation="False" />
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
<asp:TextBox Runat="server" ID="textbox1" />
<asp:RequiredFieldValidator Runat="server"
ID="requiredFieldValidator"
ControlToValidate="textbox1"
ErrorMessage="You screwed up" />
<asp:Button Runat="server" ID="mainbutton" />
</form>

In this case pressing a button in the DataGrid does not cause
validation.

--
Scott
http://www.OdeToCode.com

On Thu, 24 Jun 2004 11:20:03 +0200, "z. f."
<zi**@info-scopeREMSPAM.co.il> wrote:
Hi,

i stated that this is an advanced question because i have a post from fewdays ago that i received answers to with suggestions that looked good butdid not work, so please if you post a reply make sure your suggestion
actually works.

like a <asp:button> control have a CausesValidation property that allows
it
to POST a button command event to the server without causing the page
tomake validation on form inputs, i need to get the same functionallity to
an<asp:button> culomn with a delete command.

i tried to use the OnItemCreated event of the datagrid, to add this
property, but perhaps becuase the button inside the grid is actually an
array of buttons, setting the property had no effect.

also tried to make an <TemplateItem> with the button inside, but again
setting the property had no effect and the form did passed the
validationcheck.

please advise, but don't just throw "why don't you try this", and as it

didlast time, it did not work.

i'm gessing there must be a way (even use javascript or something) - to makea command from the grid row without passing the form validation.
TIA, z.


Nov 18 '05 #5

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

Similar topics

2
by: GrantS | last post by:
I am trying to convert the VB.Net code example povided by http://authors.aspalliance.com/JimRoss/Articles/MaintainScrollPos.aspx into C# (ASP.Net)without success. No errors are thrown in the VB...
12
by: James Norton-Jones | last post by:
Hi, Am I trying to hold the data of a DataGrid in a label so that when the form is reposted the DataGrid can be repopulated. The problem I am having is that I don't understand how to get the...
4
by: z. f. | last post by:
Hi, I'm having an aspx page with a server form. i have a grid with a delete button and below the grid, another area with inputs for inserting new values and an "add" button for submiting the...
6
by: z. f. | last post by:
Hi, i have a datagrid with a delete button for each row in the grid. when the delete button is clicked i need to ask the user in a "confirm" message box if he's sure he wants to delete. the...
7
by: Alex Maghen | last post by:
I have a DataGrid control with a LinkButton command column that deletes the row. What I want to do is set it up so that there's a client-side Confirm alert BEFORE the actual Delete command gets...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.