473,738 Members | 8,397 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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:CustomVali dator ID="MCValidator " runat="server" ControlToValida te="MCTextBox"
ErrorMessage="F ailed" />
</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.EventArg s)
Handles Me.Load
Repeater.DataSo urce = New Object() {1, 2, 3, 4, 5, 6}
Repeater.DataBi nd()
End Sub

Private Sub Repeater1_ItemC reated(ByVal sender As Object, ByVal e As
System.Web.UI.W ebControls.Repe aterItemEventAr gs) Handles Repeater.ItemCr eated
Dim Label As Label = CType(e.Item.Fi ndControl("MCLa bel"), Label)
Dim Validator As CustomValidator = CType(e.Item.Fi ndControl("MCVa lidator"),
CustomValidator )
Dim TextBox As TextBox = CType(e.Item.Fi ndControl("MCTe xtBox"), TextBox)

Label.Text = "Fred"
Validator.Contr olToValidate = TextBox.ID

AddHandler Validator.Serve rValidate, AddressOf Validator_Valid ate
End Sub
Sub Validator_Valid ate(ByVal source As Object, ByVal args As ServerValidateE ventArgs)
args.IsValid = CStr(args.Value ).Trim = "1" 'Only Validate if Text
= "1"
End Sub

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

--
Rory
Dec 3 '07 #1
1 4582
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.IsPageVali d 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.EventArg s)
Handles Me.Load
If Not Page.IsPostBack then '<----------------New "If" test
Repeater.DataSo urce = New Object() {1, 2, 3, 4, 5, 6}
Repeater.DataBi nd()
End If
End Sub

Protected Sub Button1_Click(B yVal 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
1272
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 data in the format of the user control mentioned above because the data might need many of the user control I designed to show to user. How can I do that?
1
1082
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 textbox having something in it? I don't have any javascript skills so I'm hoping that I can use the validator controls that come with asp.net
2
3251
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 RejectTxt As TextBox = CType(e.Item.FindControl("txtRejectNote"), TextBox) RejectButton(New Guid(e.CommandArgument.ToString), RejectTxt.Text) End Sub
4
1727
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. Each row has a text box for quantity to order and a button to add the product and quantity to the shopping cart. I can dynamically assign the CommandArgument to my button and figure out which one was clicked, but I can't figure out how to get the...
1
2294
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, medium, large), a price, a checkbox to say whether or not the variation is on special offer and a special price. I can pull the values out of the database OK and display them in a repeater. What I want to do is have a set of controls below the...
0
1179
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: http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&threadm=A69AC6CD-0A87-4A8B-A2AA-9719B731F2BE%40microsoft.com&rnum=1&prev=/groups%3Fq%3DInstantiateIn%2Brepeater%2Bevent%26ie%3DUTF-8%26hl%3Den%26btnG%3DGoogle%2BSearch I wish to extend the InstantiateIn code to...
8
16613
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 the repeater. When clicked, it is supposed to
1
2457
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 created a validation control that inherits from BaseValidator and performs server and client side checks and is performing the validation on the repeater control. The above all works except I cant get the client validation to stop the page from...
0
8969
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9476
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9335
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9263
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9208
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8210
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6751
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6053
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3279
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.