R
Rory Becker
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
--------------------------------------------------------
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
--------------------------------------------------------