469,947 Members | 2,176 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,947 developers. It's quick & easy.

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 1863
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by GrantS | last post: by
12 posts views Thread by James Norton-Jones | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.