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

Repeater containing a validator

Hi All

It's been a while since I tried anything like this and it's just driving
me nuts..

I want to have simple templated repeater which contains (Per item) a Label,
a textbox and a CustomValidator.
Below the Repleater is a single button witha serverside function which changes
the text of the button.

I was hoping that when I clicked the button, each row would validate and
postback would not occur if any one of the validators raised an issue.

However the button's text changes regardless of what I put in any of the
boxes.

Can someone point me in the direction of my blunder?

Thanks for any help

FYI I'm using VS2008
Code below
--------------------------------------------------------
<form id="form1" runat="server">
<div>
<asp:Repeater ID="Repeater" runat="server">
<ItemTemplate>
<asp:Label ID="MCLabel" runat="server" Text="Label"></asp:Label>
<asp:TextBox ID="MCTextbox" runat="server"/>
<asp:CustomValidator ID="MCValidator" runat="server" ControlToValidate="MCTextBox"
ErrorMessage="Failed" />
</ItemTemplate>
</asp:Repeater>
</div>
<asp:Button ID="Button1" runat="server" Text="Button" />
</form>
--------------------------------------------------------

--------------------------------------------------------
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
Repeater.DataSource = New Object() {1, 2, 3, 4, 5, 6}
Repeater.DataBind()
End Sub

Private Sub Repeater1_ItemCreated(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.RepeaterItemEventArgs) Handles Repeater.ItemCreated
Dim Label As Label = CType(e.Item.FindControl("MCLabel"), Label)
Dim Validator As CustomValidator = CType(e.Item.FindControl("MCValidator"),
CustomValidator)
Dim TextBox As TextBox = CType(e.Item.FindControl("MCTextBox"), TextBox)

Label.Text = "Fred"
Validator.ControlToValidate = TextBox.ID

AddHandler Validator.ServerValidate, AddressOf Validator_Validate
End Sub
Sub Validator_Validate(ByVal source As Object, ByVal args As ServerValidateEventArgs)
args.IsValid = CStr(args.Value).Trim = "1" 'Only Validate if Text
= "1"
End Sub

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
Handles Button1.Click
Button1.Text = "Worked"
End Sub
--------------------------------------------------------

--
Rory
Dec 3 '07 #1
1 4550
Ok this seems to have been the result of 2 issues.

1.I should not have been redatabinding on postback. Ie I should test "if
not isPostback" before performing databind in the Page_Load

2.I need to check Page.IsPageValid to determine server side if any validators
have detected non-compliance.

Changes needed to make code work are

--------------------------------------------------------
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
If Not Page.IsPostBack then '<----------------New "If" test
Repeater.DataSource = New Object() {1, 2, 3, 4, 5, 6}
Repeater.DataBind()
End If
End Sub

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
Handles Button1.Click
If Not Page.IsValid Then '<----------------New "If" test
Exit Sub
End If
Button1.Text = "Worked"
End Sub
--------------------------------------------------------

--
Rory
Dec 3 '07 #2

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

Similar topics

0
by: MeiMei | last post by:
Hi, I have designed a user control which exposes properties for data binding in the containing web page, and I want to use the Repeater web control in the containing web page to display all the...
1
by: Simon | last post by:
Hi all, I have a repeater that is going to show a number of text boxes -two per row in fact. Does anyone know how I could go about ensuring that the user can't proceed without each and every...
2
by: Jerrad | last post by:
I have a textbox and a button within a repeater. The OnItemCommand sub of the repeater looks like this: Sub RepeaterButtonSub(ByVal source As Object, ByVal e As RepeaterCommandEventArgs) Dim...
4
by: bob garbados | last post by:
I need to create a page that displays all of the products from a table and allows for add to cart functionality. My thoughts were to display all of the products in table rows using a repeater. ...
1
by: Alan Silver | last post by:
Hello, I have a page in which I'm trying to give the user the chance to manipulate a list of items. These are the price variations for a product, so each item consists of a name (eg, small,...
0
by: Gordon Smith | last post by:
Hi, Am writing a server control which contains a repeater control. I followed the code outlined by Rachel@discussions.microsoft.com (many thanks) on the following thread: ...
8
by: Alan Silver | last post by:
Hello, I have a repeater that has code like this... <ItemTemplate> <asp:CheckBox ID="chkDelete" Text="" RunAt="server"/> .... other stuff goes here </ItemTemplate> There is a button below...
1
by: criz | last post by:
Hi All, I have a repeater that required a check box on each item in the repeater to be validated against eachother (to check if only one item's checkbox is ticked.) To perform this validation I...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...

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.