The ControlToValidate property of 'passwordCompare' cannot be blank - asp.net

In my page I have repeater using which I dynamically generate two textboxes & I have one compare validator.
Now for this validator I want to set ControlTovalidate & ControlToCompare.
Id of both will come from two textboxes which are generated dynamically.
So while binding these textboxes to repeater I am setting both properties of validator But error comes as "The ControlToValidate property of 'passwordCompare' cannot be blank."
<asp:repeater id="repeater" runat="server" onitemdatabound="BoundProperty">
<itemtemplate>
<asp:panel id="panelProperty" runat="server" cssclass="prop">
<asp:textbox id="textboxOrg" runat="server" cssclass="edit" visible="false"/>
</asp:panel>
</itemtemplate>
</asp:repeater>
<asp:comparevalidator id="passwordCompare" runat="server" controltovalidate="" controltocompare="" errormessage="CompareValidator"></asp:comparevalidator>

Related

How to add child object to textbox in asp.net?

I want to add child object to a TextBox, but this code gives an error
How can I achieve this?
<asp:TextBox ID="TextBox2" runat="server">
<asp:Label runat="server" Text="Label"></asp:Label>
</asp:TextBox>`
TextBox and Label are two different controls. You cant nest a Label inside a text Box.
Eg:
<asp:Label runat="server" Text="Label"></asp:Label>
<asp:TextBox ID="TextBox2" runat="server"> </asp:TextBox>
What do you want to do here?
As there are some of the ASP.NET controls like Linkbutton which allows you to hold HTML controls inside them
<asp:LinkButton ID="lnkDelete" runat="server" CssClass="remove">
<span><font color="#fb4202">x</font> Remove</span>
</asp:LinkButton>
but it is not possible to hold a asp:Label in a asp:Textbox control
What you are trying to do is impossible. While WPF has a framework that enables this kind of things, HTML and thus ASP.NET does not.
If you are trying to set the text, try this:
<asp:TextBox ID="TextBox2" runat="server" Text="abc" />
Else, just put them side by side:
<asp:Label runat="server" Text="Label" />
<asp:TextBox ID="TextBox2" runat="server" />
Textbox is a Editable Control and Label is non-Editable Control, so you can't put Label inside TextBox. You can Put Label Just Before The Textbox as :
<asp:Label ID="Label1" runat="server" Text="Enter Text"><asp:Label>
<asp:TextBox ID="txtValue" runat="server"/>

asp.net FormView Data Binding with a Collection of Data

I have a collection of records, each record has an ID and a description.
Now in my formview I have 8 textboxes and I want each text box to hold description
of each record.
So if I do this
Text='<%# Eval("Record[0].Description") %>' />
This gives an error, any other way to do it?
Also can I do it in the markup, or do I need to do it in code behind, under databound method for the formview?
Thanks..
FormView is not meant for showing List of Data.
If you have a List of Data, then you should use GridView or ListView.
Bind your FormView with a datasource having single record and then directly Eval the fields of the datasource.
i.e. do this:
<asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSourceId">
<ItemTemplate>
<asp:TextBox id="txtDescription"
Text='<%# Eval("Description") %>' />
<asp:TextBox id="txtName"
Text='<%# Eval("Name") %>' />
..
</ItemTemplate>
</asp:FormView>
so basically, your FormView should contain different DataField and it should be bound to a DataSource having just one Item.
You could use a repeater inside:
<asp:repeater ID="rep" runat="server" DataSource='<%# Eval("Record") &>'>
<ItemTemplate>
<asp:textbox id="txt" runat="server" Text='<%# Eval("Description") &>' />
</ItemTemplate>
</asp:repeater>
In the repeater you will bind to your outer datasource, inside the repeater your datacontext is the record

How to change a BoundField's control in asp.net

Can you change a BoundField's Control?
<asp:BoundField DataField="week1" HeaderText="week1" SortExpression="beginDate" />
You can't change the control that's created when you use a BoundField - that's chosen automatically based on the data type of the field you're binding to (a CheckBox gets created for boolean fields, a Label for text-type fields).
You need to use a TemplateField if you want to bind your data to a different type of control:
<asp:templatefield headertext="week1">
<itemtemplate>
<asp:label id="weekOneLbl" Text= '<%# Eval("week1") %>' runat="server"/>
</itemtemplate>
</asp:templatefield>
By default, your BoundField will use a Label control (like above). But with the TemplateField, you could change it to, say, a read-only TextBox:
<asp:templatefield headertext="week1">
<itemtemplate>
<asp:TextBox ID="weekOneLbl" Text= '<%# Eval("week1") %>' runat="server" ReadOnly="True" />
</itemtemplate>
</asp:templatefield>

How to set ItemTemplate text value to combobox DataTextField instead of DataValueField

I have a telerik radgrid with a GridTemplateColumn as seen below in a C# ASP.NET 4.0 webform.
As you can see, in the EditItemTemplate I am using a RadComboBox with an id number for DataValueField and a human readable text for DataTextField.
My question is, how can I change the Text in my ItemTemplate to show the human readable value instead of the Id? The value Alias1 comes from the grid datasource and it is the Id.
Thank you for any help you can provide!
<telerik:GridTemplateColumn UniqueName="Alias1" Display="true" DataField="Alias1" HeaderText="Alias1" SortExpression="Alias1">
<ItemTemplate>
<asp:Label ID="lblField30" CssClass="text" runat="server" Text='<%# Bind("Alias1") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<telerik:RadComboBox ID="RadComboBox16" runat="server" Skin="Outlook" Height="150" DataSourceID="SqlDataSourceAliasOptions" DataTextField="aliasText" DataValueField="aliasid" SelectedValue='<%#Bind("Alias1") %>'>
</telerik:RadComboBox>
</EditItemTemplate>
</telerik:GridTemplateColumn>
You need to change ItemTemplate binding like this:
<ItemTemplate>
<asp:Label ID="lblField30" CssClass="text" runat="server" Text='<%# Eval("aliasText") %>'></asp:Label>
</ItemTemplate>
Of course your binded entity must have "aliasText" property. If you are binding something like DataTable make sure that contains "aliasText" column.

Getting textbox value inside a Detailsview control

I have a DetailsView control with a template field as follows:
<asp:TemplateField SortExpression="Title">
<ItemTemplate>
<asp:TextBox ID="txtMessageTitle" Text='<%# Bind("Title") %>' runat="server">
</asp:TextBox>
<asp:Button ID="btnUpdateTitle" runat="server" Text="Update"
CommandName="UpdateTitle" CommandArgument='<%# Bind("MessageID") %>' oncommand="btnUpdateCommand"/>
</ItemTemplate>
</asp:TemplateField>
The Details View is wrapped inside an UpdatePanel.
When the user clicks on btnUpdateButton I'd like to be able to retrieve the textbox (txtMessageTitle) value in code behind and by using CommandArgument of the button, update the appropriate MessageTitle in database. How can I retrieve the textbox value inside the DetailsView control from the Command event of my button?
Thanks.
use the following:
TextBox txtMessageTitle = detailsViewName.FindControl("txtMessageTitle") as TextBox;
string text = txtMessageTitle.Text;

Resources