I'm using a formview to insert a new record in my database (beta 2).
Everything works fine until I add a requiredfieldvalidator to validate the content of a textbox (bound to one of the parameter of the datasource) in the insertitemtemplate.
With the validator on the page, the page just posts back and nothing happens.
The problem does not appear when I use another type of validator (or no validators at all)
It seems that the validation event fires again on the postback just before the content of the textbox is retrieved (from the viewstate I suppose).
Here's my code.
The same problem I had today too. I had to change my all formview.insertitem-updateitem methods with parameter value false. In earlier versions of vs2005 it worked fine.
yes, you're right: in my example a click over the button will not result in the insertion of a new item because i didn't set the commandname property to inser. however, i uas under the impression that the problem was related with the validation controls not
working and letting you submit the page even when it has errors. now it looks to me like the problem is related with the fact that the formview control is not inserting a new record on the db when everything is ok. is this the problem you're having?
--
Regards,
Luis Abreu
email: labreu_at_gmail.com
EN blog:http://msmvps.com/blogs/luisabreu
I think that kaanoezturk is having exactly the same problem.
This is a bug in beta 2 : the insert commandname calls the insertitem(true) (meaning w/ validation) resulting in a validation on empty fields (because the content of the textbox is not yet retrieved from the viewstate...). It should call insertitem(false)...
I am having a similar problem. FormView command buttons do not raise their appropriate commands in the Form. For example, Insert does not raise the ObjectDataSource's INSERT method. It use to work fine. Now I have to go in and put OnClick events for the
FormView command buttons when they used to be able to just do the command.
I have not done anything with these files lately. I don't understand why it would work this morning and then not later today. Can anyone help with this? I am using the AJAX Extensions and AJAX Control Tool Kit. But even when i take those out the issue still
remains. I'd hate to have to go in and code in the FormView changing modes when the Edit button is clicked and then code the Cancel button's onClick event to go back to readonly.
It is like the meaning of the command names have been lost.
Well after some more inspection I found that the page renders to a content-type of text/plain not text/html and the form tag does not render. Instead, the output starts:
b3b
2826|updatePanel|ctl00_cphCenter_upPanel|
So, now I have to figure out why it is not rendering to HTML. But at least it is some progress. I've gotta say hooray to Fiddler for helping me figure this out. So has anyone run into this kind of thing before?
marival
Member
20 Points
4 Posts
RequiredFieldValidator problem with FormView
Aug 10, 2005 01:17 PM|LINK
I'm using a formview to insert a new record in my database (beta 2).
Everything works fine until I add a requiredfieldvalidator to validate the content of a textbox (bound to one of the parameter of the datasource) in the insertitemtemplate.
With the validator on the page, the page just posts back and nothing happens.
The problem does not appear when I use another type of validator (or no validators at all)
It seems that the validation event fires again on the postback just before the content of the textbox is retrieved (from the viewstate I suppose).
Here's my code.
<asp:FormView ID="fvMessage" runat="server" DataSourceID="odsMessages" OnItemInserting="fvMessage_ItemInserting" DefaultMode="Insert">
<InsertItemTemplate>
<table border="0">
<tr>
<td>
<asp:Localize runat="server" Text="<%$Resources:Glossary,Recipient %>" /> :</td>
<td>
<asp:dropDownList ID="ddlRecipient" runat="server" DataSourceID="odsRecipients"
DataTextField="Name" DataValueField="UserName" /></td>
</tr>
<tr>
<td>
<asp:Localize runat="server" Text="<%$Resources:Glossary,Subject %>" /> :</td>
<td>
<asp:TextBox ID="tbSubject" runat="server" Text='<%# Bind("subject") %>' EnableViewState="true" /><asp:requiredfieldvalidator ID="rfv" runat="server" Controltovalidate="tbSubject" text="error" validationgroup="test"/></td>
</tr>
<tr>
<td>
<asp:Localize runat="server" Text="<%$Resources:Glossary,Content %>" /> :</td>
<td>
<asp:textbox ID="tbContent" runat="server" Text='<%# Bind("content") %>' /></td>
</tr>
<tr>
<td colspan="2">
</td>
</tr>
<tr>
<td colspan="2">
<asp:linkbutton ID="lbtnSend" runat="server" Text='<%$ Resources:Glossary, Send %>'
CommandName="Insert" ValidationGroup="test" CausesValidation="true" /></td>
</tr>
</table>
</InsertItemTemplate>
</asp:FormView>
Any idea ?
Is it a bug ?
Luis Abreu
All-Star
25674 Points
5369 Posts
MVP
Re: RequiredFieldValidator problem with FormView
Aug 10, 2005 09:35 PM|LINK
what do you mean by the page just posts back?I've tried this code:
<asp:FormView runat="server" ID="t" DefaultMode="insert">
<InsertItemTemplate>
<asp:TextBox runat="server" ID="txt"></asp:TextBox>
<asp:RequiredFieldValidator runat="server" ID="i" ControlToValidate="txt" Text="*" EnableClientScript="true" ValidationGroup="I" />
<asp:Button runat="Server" ID="vt" Text="O" ValidationGroup="I" />
</InsertItemTemplate>
</asp:FormView>
and everything worked out as expected. does this work for you?
Regards,
Luis Abreu
email: labreu_at_gmail.com
EN blog:http://msmvps.com/blogs/luisabreu
marival
Member
20 Points
4 Posts
Re: RequiredFieldValidator problem with FormView
Aug 11, 2005 10:22 AM|LINK
What I mean by "the page just posts back" is that the page refreshes but nothing has changed on it and the record is not inserted.
In your example, your button does not trigger the insert event as it doesn't explicitly call the "Insert" command (CommandName = "Insert").
Do you actually manage to insert records ?
Thank you for your help. (by the way, your code has the same effect on my computer than mine > no errors but no record inserted).
marival
Member
20 Points
4 Posts
Re: RequiredFieldValidator problem with FormView
Aug 11, 2005 10:45 AM|LINK
{
formview.InsertItem(false);
}
instead of using CommandName="Insert" for my button.
Looks like that way to proceed fired the validation again, at a really bad time.
It's not really satisfying though.
kaanoezturk
Member
655 Points
140 Posts
Re: RequiredFieldValidator problem with FormView
Aug 11, 2005 11:03 AM|LINK
Luis Abreu
All-Star
25674 Points
5369 Posts
MVP
Re: RequiredFieldValidator problem with FormView
Aug 11, 2005 12:12 PM|LINK
yes, you're right: in my example a click over the button will not result in the insertion of a new item because i didn't set the commandname property to inser. however, i uas under the impression that the problem was related with the validation controls not working and letting you submit the page even when it has errors. now it looks to me like the problem is related with the fact that the formview control is not inserting a new record on the db when everything is ok. is this the problem you're having?
Regards,
Luis Abreu
email: labreu_at_gmail.com
EN blog:http://msmvps.com/blogs/luisabreu
marival
Member
20 Points
4 Posts
Re: RequiredFieldValidator problem with FormView
Aug 11, 2005 01:41 PM|LINK
I think that kaanoezturk is having exactly the same problem.
This is a bug in beta 2 : the insert commandname calls the insertitem(true) (meaning w/ validation) resulting in a validation on empty fields (because the content of the textbox is not yet retrieved from the viewstate...). It should call insertitem(false)...
Thanks kaanoezturk by the way !
ninatang
Member
575 Points
115 Posts
AspNetTeam
Re: RequiredFieldValidator problem with FormView
Aug 23, 2005 11:10 PM|LINK
cloak13PLAGUE
Member
20 Points
8 Posts
Re: RequiredFieldValidator problem with FormView
Jan 10, 2008 06:24 PM|LINK
I am having a similar problem. FormView command buttons do not raise their appropriate commands in the Form. For example, Insert does not raise the ObjectDataSource's INSERT method. It use to work fine. Now I have to go in and put OnClick events for the FormView command buttons when they used to be able to just do the command.
I have not done anything with these files lately. I don't understand why it would work this morning and then not later today. Can anyone help with this? I am using the AJAX Extensions and AJAX Control Tool Kit. But even when i take those out the issue still remains. I'd hate to have to go in and code in the FormView changing modes when the Edit button is clicked and then code the Cancel button's onClick event to go back to readonly.
It is like the meaning of the command names have been lost.
Please help!
Thanks,
Tim Kulp
cloak13PLAGUE
Member
20 Points
8 Posts
Re: RequiredFieldValidator problem with FormView
Jan 10, 2008 07:17 PM|LINK
Well after some more inspection I found that the page renders to a content-type of text/plain not text/html and the form tag does not render. Instead, the output starts: