Ajax for asp.net form view - asp.net

Inside form view I have drop down list on selected index change I have text box appearing.
Now I want to keep both these drop down and Text box inside Ajax update panel. Upon click button out side update panel I want to save these two fields as well.
Any help Much appreciated.
Here aspx code
<asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' />
<br />
<asp:DropDownList ID="ddlLName"
runat="server" ValidationGroup="VG1" SelectedValue='<%# Bind("LNAMEIFYES") %>' OnSelectedIndexChanged="ddlLName_SelectedIndexChanged" AutoPostBack="True">
<asp:ListItem Value="">Please select...</asp:ListItem>
<asp:ListItem Value="1">Yes</asp:ListItem>
<asp:ListItem Value="2">No</asp:ListItem>
</asp:DropDownList>
<br />
<asp:Panel ID="pnlLNAme" runat="server" Visible="false">
LName:
<asp:TextBox ID="LNameTextBox" runat="server" Text='<%# Bind("LName") %>' />
<br />
</asp:Panel>
Code Behind
protected void ddlLName_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList ddlLName = (DropDownList)FormView1.FindControl("ddlLName");
if (ddlLName.SelectedValue == "1")
{
Panel pnlLNAme = (Panel)FormView1.FindControl("pnlLNAme");
pnlLNAme.Visible = true;
}
else
{
Panel pnlLNAme = (Panel)FormView1.FindControl("pnlLNAme");
pnlLNAme.Visible = false;
}
}

I solved the problem by using by using two update panals, using trigger in one of the update panal.
<EditItemTemplate>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
ID:
<asp:Label ID="IDLabel1" runat="server" Text='<%# Eval("ID") %>' />
<br />
Name:
<asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' />
<br />
<asp:DropDownList ID="ddlLName"
runat="server" ValidationGroup="VG1" SelectedValue='<%# Bind("LNAMEIFYES") %>' OnSelectedIndexChanged="ddlLName_SelectedIndexChanged" AutoPostBack="True">
<asp:ListItem Value="">Please select...</asp:ListItem>
<asp:ListItem Value="1">Yes</asp:ListItem>
<asp:ListItem Value="2">No</asp:ListItem>
</asp:DropDownList>
<br />
<asp:Panel ID="pnlLNAme" runat="server" Visible="false">
LName:
<asp:TextBox ID="LNameTextBox" runat="server" Text='<%# Bind("LName") %>' />
<br />
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
Salary:
<asp:TextBox ID="SalaryTextBox" runat="server" Text='<%# Bind("Salary") %>' />
<br />
IsActive:
<asp:CheckBox ID="IsActiveCheckBox" runat="server" Checked='<%# Bind("IsActive") %>' />
<br />
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update" Text="Update" />
<asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="UpdateButton" EventName="Click_Enent" />
</Triggers>
</asp:UpdatePanel>
</EditItemTemplate>

Related

How to loop through controls within a gridview and store their values in an array?

please excuse this potentially long post as I feel like most of the information I will add below is necessary. As the title states I am trying to loop through a collection of controls that are within a gridview on my page (there are 2 gridviews actually, but they are identical in behavior) and store the values of some of these controls in an array that I can use to perform other functions.
To start I have added the code for the gridview below.
<asp:Panel ID="gridPNL1" runat="server">
Repair / Labor<asp:LinkButton runat="server" ID="lbAddRepair" Text="Add New Repair / Labor" CommandName="AddLabor" OnClick="AddObject_Click" Enabled="false" style="margin-left:20px" Visible="false" />
<asp:GridView ID="GridView1" runat="server"
EmptyDataText="No Claimed Labor" AutoGenerateColumns="False"
ShowHeaderWhenEmpty="True" DataKeyNames="RecID"
ShowFooter="True" DataSourceID="SqlDataSource6" Width="95%">
<RowStyle HorizontalAlign="Center" />
<EmptyDataTemplate>
<asp:DropDownList ID="ddlRepairEquipmentNew" runat="server" DataSourceID="SqlDataSourcePartEquipment" DataValueField="RecID"
DataTextField="EquipmentPart" AppendDataBoundItems="True" AutoPostBack="True" Width="220px" Height="20px"
Style="margin-left: 70px;" > <%-- Removed the OnSelectedIndexChanged (add if needed) --%>
<asp:ListItem Value ="0">---SELECT---</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="ddlRepairNew" runat="server" DataSourceID="SqlDataSourceRepair" DataValueField="RecID"
DataTextField="Description" AppendDataBoundItems="True" Width="220px" Height="20px" AutoPostBack="true"
style="" OnSelectedIndexChanged="ddlRepairNew_SelectedIndexChanged"
OnDataBinding="ddlRepairNew_DataBinding">
<asp:ListItem Value="0">---SELECT---</asp:ListItem>
</asp:DropDownList>
<%-- <asp:textbox ID="txtDescOther" runat="server" Width="235px" Visible="false" />--%>
<asp:textbox runat="server" ID="txtRepairHoursNew" Width="95px" style="margin-left: 68px"/>
<%--<asp:Label runat="server" ID="lblRepairHoursAllowed"></asp:Label>--%>
<asp:HiddenField runat="server" ID="hidAllowedRepairHoursNew" />
<%-- <asp:textbox ID="txtAllowedHoursNew" runat="server" Width="90px"/>--%>
<asp:textbox ID="txtRepairCostNew" runat="server" Width="95px" ReadOnly="True"/>
<asp:textbox ID="txtLineTotalNew" runat="server" Width="95px" ReadOnly="true"/>
<asp:textbox ID="txtTaxNew" runat="server" Width="95px" text="0"/>
<asp:Button ID="InsertDetail" runat="server" CommandName="InsertDetail" Height="25px" Text="Add Detail" Width="85px" />
</EmptyDataTemplate>
<AlternatingRowStyle BackColor="#CCCCCC" />
<Columns>
<asp:CommandField ShowEditButton="True" footertext="Add -->" ShowDeleteButton="True" HeaderStyle-Width="70px"/>
<asp:BoundField DataField="RecID" HeaderText="RecID" SortExpression="RecID" ReadOnly="True" Visible="False" />
<asp:TemplateField HeaderText="Equipment / Repair / Labor Description" ItemStyle-HorizontalAlign="center" >
<ItemTemplate>
<asp:Label ID="lblRepairEquipmentType" Text='<%# Bind("EquipmentType") %>' runat="server" Enabled="False" Width="220px" />
<asp:label ID="lblRepairType" Text='<%# Bind("RepairType") %>' runat="server" Enabled="False" Width="220px"/>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="ddlRepairEquipmentEdit" runat="server" DataSourceID="SqlDataSourcePartEquipment" DataValueField="RecID" DataTextField="EquipmentPart" SelectedValue='<%# Eval("EquipmentID") %>' AppendDataBoundItems="True" AutoPostBack="True" Width="220px" Height="20px" >
<asp:ListItem Value="0">---SELECT---</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="ddlRepairEdit" runat="server" DataSourceID="SqlDataSourceRepair" DataValueField="RecID" DataTextField="Description" SelectedValue='<%# Eval("RepairID")%>' AppendDataBoundItems="True" AutoPostBack="true" Width="220px" Height="20px" OnSelectedIndexChanged="ddlRepairEdit_SelectedIndexChanged" />
</EditItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="ddlRepairEquipmentInsert" runat="server" DataSourceID="SqlDataSourcePartEquipment" DataValueField="RecID" DataTextField="EquipmentPart" AppendDataBoundItems="True" AutoPostBack="True" Width="220px" Height="20px" Style="margin-left: 29px" >
<asp:ListItem Value="0">---SELECT---</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="ddlRepairInsert" runat="server" DataSourceID="SqlDataSourceRepair" DataValueField="RecID" DataTextField="Description" AppendDataBoundItems="True" autopostback="true" Width="220px" Height="20px" OnSelectedIndexChanged="ddlRepairInsert_SelectedIndexChanged" OnDataBinding="ddlRepairInsert_DataBinding">
<asp:ListItem Value="0">---SELECT---</asp:ListItem>
</asp:DropDownList>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Repair Hours Requested" ItemStyle-HorizontalAlign="center" HeaderStyle-Width="100px">
<ItemTemplate>
<asp:label ID="lblRepairHours" Text='<%# Bind("RepairHours")%>' runat="server" />
</ItemTemplate>
<EditItemTemplate>
<asp:textbox ID="txtRepairHoursEdit" Text='<%# Bind("RepairHours")%>' runat="server" Width="95px" />
<%--<asp:Label ID="lblRepairHoursEdit" runat="server"></asp:Label>--%>
<asp:HiddenField runat="server" ID="hidAllowedRepairHoursEdit" Value='<%# Bind("AllowedHours")%>' />
</EditItemTemplate>
<FooterTemplate>
<asp:textbox ID="txtRepairHoursInsert" runat="server" style="width: 100%; box-sizing: border-box;"/>
<%--<center><asp:Label ID="lblRepairHoursInsert" runat="server"></asp:Label></center>--%>
<asp:HiddenField runat="server" ID="hidAllowedRepairHoursInsert" />
</FooterTemplate>
</asp:TemplateField>
<%--<asp:TemplateField HeaderText="Repair Hours Approved" ItemStyle-HorizontalAlign="center" HeaderStyle-Width="100px">
<ItemTemplate>
<asp:label ID="lblAllowedHours" Text='<%# Bind("AllowedHours")%>' runat="server" Width="50px"/>
</ItemTemplate>
<EditItemTemplate>
<asp:textbox ID="txtAllowedHoursEdit" Text='<%# Bind("AllowedHours")%>' Enabled="true" runat="server" Width="50px"/>
</EditItemTemplate>
<FooterTemplate>
<asp:textbox ID="txtAllowedHoursInsert" Text='<%# Bind("AllowedHours")%>' runat="server" style="width: 100%; box-sizing: border-box;"/>
</FooterTemplate>
</asp:TemplateField>--%>
<asp:TemplateField HeaderText="Repair Cost" ItemStyle-HorizontalAlign="center" HeaderStyle-Width="100px">
<ItemTemplate>
<asp:label ID="lblRepairCost" Text='<%# Bind("RepairCost", "{0:C}") %>' runat="server" Enabled="False"/>
</ItemTemplate>
<EditItemTemplate>
<asp:textbox ID="txtRepairCostEdit" Text='<%# Bind("RepairCost") %>' runat="server" ReadOnly="True" Width="95px"/>
</EditItemTemplate>
<FooterTemplate>
<asp:textbox ID="txtRepairCostInsert" Text='<%# Bind("RepairCost") %>' runat="server" ReadOnly="True" style="width: 100%; box-sizing: border-box;"/>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Repair Total" ItemStyle-HorizontalAlign="Center" HeaderStyle-Width="100px">
<ItemTemplate>
<asp:label ID="lblRepairTotal" Text='<%# Bind("LaborRequested", "{0:C}")%>' runat="server" />
</ItemTemplate>
<EditItemTemplate>
<asp:textbox ID="txtRepairTotalEdit" Text='<%# Bind("LaborRequested")%>' Enabled="false" runat="server" Width="95px"/>
</EditItemTemplate>
<FooterTemplate>
<asp:textbox ID="txtRepairTotalInsert" Text='<%# Bind("LaborRequested") %>' runat="server" Enabled="false" style="width: 100%; box-sizing: border-box;"/>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Tax" ItemStyle-HorizontalAlign="Center" HeaderStyle-Width="100px">
<ItemTemplate>
<asp:LinkButton ID="lbTaxTotal" Text='<%# Bind("Tax", "{0:C}")%>' runat="server" CommandArgument="Repair" OnClick="lblTaxTotal_Click" />
<asp:HiddenField ID="hidRepairGST" runat="server" Value='<%# Bind("GST")%>' />
<asp:HiddenField ID="hidRepairPST" runat="server" Value='<%# Bind("PST")%>' />
<asp:HiddenField ID="hidRepairQST" runat="server" Value='<%# Bind("QST")%>' />
<asp:HiddenField ID="hidRepairHST" runat="server" Value='<%# Bind("HST")%>' />
</ItemTemplate>
<EditItemTemplate>
<asp:textbox ID="lblTaxTotalEdit" Text='<%# Bind("Tax")%>' Enabled="true" runat="server" Width="95px"/>
</EditItemTemplate>
<FooterTemplate>
<asp:textbox ID="txtTaxTotalInsert" runat="server" Enabled="true" text="0" style="width: 100%; box-sizing: border-box;"/>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Insert New" HeaderStyle-Width="85px">
<ItemTemplate>
<asp:Label ID="lblEmpty" Text="" runat="server" Width="85px"/>
</ItemTemplate>
<FooterTemplate>
<asp:Button ID="Insert" runat="server" CommandName="InsertNewDetail" Height="22px" Text="Insert" style="width: 100%; box-sizing: border-box;" />
</FooterTemplate>
</asp:TemplateField>
</Columns>
<HeaderStyle BackColor="#336699" ForeColor="White" />
</asp:GridView>
<asp:Label runat="server" ID="lblErrorRepair" ForeColor="Red" />
<br />
</asp:Panel>
What I am trying to do with the gridview above is loop through some specific controls on the gridview and store their values in an array. Essentially how this gridview works is the user will enter information into a series of drop down lists and textboxes, as seen above, when the user hits the button at the end of the row (labeled "InsertDetail" and "Insert" respectively, it takes the data from the drop down list and textboxes and stores it in the labels (also above) for simpler display (this goes on for however many items the user needs to enter (usually around 2 - 5 items total)). I need a way to loop through the values in however many iterations of "lblRepairEquipmentType" there are at the time the user hits any of the "insert" buttons and store the value of each iteration of "lblRepairEquipmentType" in an array so that I can use that array to perform other procedures.
Any help would be greatly appreciated and if there is something else I can try that would be better, either efficiency wise or just for best practices I would appreciate and welcome any constructive criticism. Thank you all for your patience and willingness to help.

perform validation on multiple buttons

I have two section of elements inside the form (e.g. pizza and burger).
Each section has different fields and each section has its own submit button.
Now I want to validate each of these section only if their corresponding submit button is pressed. If the other submit button is pressed, it should not validate other section of elements.
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:Panel ID="Panel2" runat="server" GroupingText="Burger" BackImageUrl="~/finalll/check 24/check 24/images/background-burger.jpg"
Width="684px">
<asp:Label ID="burgertype" runat="server" Text="Burger Type" Width="249px"></asp:Label><br />
<asp:DropDownList ID="DropDownListburger" AppendDataBoundItems="true" runat="server"
OnLoad="DropDownListburger_Load">
<asp:ListItem Text="<Select One>" Value="" />
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidatorbtype" runat="server" InitialValue=""
ControlToValidate="DropDownListburger" ForeColor="Red" ErrorMessage="*"></asp:RequiredFieldValidator>
<br />
<asp:Label ID="burgersize" runat="server" Text="Burger Size" Width="249px"></asp:Label><br />
<asp:DropDownList ID="DropDownbsize" runat="server">
<asp:ListItem Text="Select One" Value=""></asp:ListItem>
<asp:ListItem Text="small" Value="small"></asp:ListItem>
<asp:ListItem Text="medium" Value="medium"></asp:ListItem>
<asp:ListItem Text="large" Value="large"></asp:ListItem>
<asp:ListItem Text="Extra Large" Value="Extra Large"></asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidatorbsize" runat="server" InitialValue=""
ControlToValidate="DropDownbsize" ForeColor="Red" ErrorMessage="*"></asp:RequiredFieldValidator>
<br />
<asp:Label ID="Labelquantity2" runat="server" Text="Quantity" Width="249px"></asp:Label><br />
<asp:TextBox ID="TextBoxquantity2" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidatorquanty2" runat="server" Text="*"
ControlToValidate="TextBoxquantity2" ForeColor="Red"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidatorquanty2" runat="server"
ErrorMessage="Enter Valid Quantity" ControlToValidate="TextBoxquantity2" CssClass="requiredFieldValidateStyle"
ForeColor="Red" ValidationExpression="[0-9]+">
</asp:RegularExpressionValidator>
<br />
<asp:Button ID="Buttonburger" runat="server" Text="submit" OnClick="Buttonburger_Click" />
</asp:Panel>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Buttonburger" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Panel ID="Panel1" runat="server" GroupingText="Pizza" BackImageUrl="~/finalll/check 24/check 24/images/1380310811-pitstsa-ch1--39.jpg"
Width="684px">
<asp:Label ID="Pizzatype" Text="Pizza Type" runat="server"></asp:Label>
<br />
<asp:DropDownList ID="dropdwnpizza" AppendDataBoundItems="true" runat="server" OnLoad="dropdwnpizza_Load">
<asp:ListItem Text="<Select One>" Value="" />
</asp:DropDownList>
<asp:RequiredFieldValidator ID="rfqdropdwnpizza" runat="server" InitialValue="" ControlToValidate="dropdwnpizza"
ForeColor="Red" ErrorMessage="*"></asp:RequiredFieldValidator>
<br />
<asp:Label ID="pizzasize" Text="Pizza Size" runat="server"></asp:Label><br />
<asp:DropDownList ID="DropDwnsize" runat="server">
<asp:ListItem Text="Select One" Selected="True" Value=""></asp:ListItem>
<asp:ListItem Text="small" Value="small"></asp:ListItem>
<asp:ListItem Text="medium" Value="medium"></asp:ListItem>
<asp:ListItem Text="large" Value="large"></asp:ListItem>
<asp:ListItem Text="Extra Large" Value="Extra Large"></asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="rfqpizzasize" runat="server" InitialValue="" ControlToValidate="DropDwnsize"
ForeColor="Red" ErrorMessage="*"></asp:RequiredFieldValidator>
<br />
<asp:Label ID="Labelquantity" runat="server" Text="Quantity" Width="249px"></asp:Label><br />
<asp:TextBox ID="TextBoxquantity" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="pprc" runat="server" Text="*" ControlToValidate="TextBoxquantity"
ForeColor="Red"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidatorpprc" runat="server"
ErrorMessage="Enter Valid Quantity" ControlToValidate="TextBoxquantity" CssClass="requiredFieldValidateStyle"
ForeColor="Red" ValidationExpression="[0-9]+">
</asp:RegularExpressionValidator>
<asp:Button ID="Buttonpizza" runat="server" Text="submit" OnClick="Buttonpizza_Click" />
</asp:Panel>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Buttonpizza" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
You need to use Validation Groups, from MSDN -
Validation groups allow you to organize validation controls on a page
as a set. Each validation group can perform validation independently
from other validation groups on the page.
For example (from MSDN):
<asp:requiredfieldvalidator id="RequiredFieldValidator2"
controltovalidate="AgeTextBox"
validationgroup="PersonalInfoGroup"
errormessage="Enter your age."
runat="Server">
</asp:requiredfieldvalidator>
<!--When Button1 is clicked, only validation controls that are a part of PersonalInfoGroup
are validated.-->
<asp:button id="Button1"
text="Validate"
causesvalidation="true"
validationgroup="PersonalInfoGroup"
runat="Server" />

how to check if textbox is not empty in formview

i have a page where i can create users that can then log into the page. on the page where i create the users, there is a formview. in this formview there are multiple textboxes and dropdownlists. how can i check if the textboxes are empty? i tried to do it code-behind but i cant access the textboxes from there...
here is my code:
<asp:FormView ID="fvBenutzer" runat="server" DefaultMode="Insert" DataKeyNames="BenutzerID" DataSourceID="SqlDataSource1">
<InsertItemTemplate>
Gruppe:
<asp:TextBox ID="tbGruppe" runat="server" Text='<%# Bind("GruppenID") %>' /><br />
Titel:
<asp:TextBox ID="tbTitel" runat="server" Text='<%# Bind("Titel") %>' /><br />
Bezeichnung:
<asp:DropDownList AppendDataBoundItems="true" runat="server" ID="ddwnBezeichnung" Text='<%# Bind("Bezeichnung")%>'>
<asp:ListItem Text="Mitarbeiter" Value="Mitarbeiter"></asp:ListItem>
<asp:ListItem Text="Praktikant" Value="Praktikant"></asp:ListItem>
<asp:ListItem Text="Azubi" Value="Azubi"></asp:ListItem>
<asp:ListItem Text="Umschüler" Value="Umschüler"></asp:ListItem>
</asp:DropDownList><br />
Vorname:
<asp:TextBox runat="server" ID="tbVorname" Text='<%# Bind("Vorname")%>' /><br />
Nachname:
<asp:TextBox runat="server" ID="tbNachname" Text='<%# Bind("Nachname")%>' /><br />
Geburtsdatum:
<asp:TextBox runat="server" ID="tbGeburtsdatum" Text='<%# Bind("Geburtsdatum")%>' /><br />
Geburtsort:
<asp:TextBox runat="server" ID="tbGeburtsort" Text='<%# Bind("Geburtsort")%>' /><br />
Nationalität:
<asp:TextBox runat="server" ID="tbNationalitaet" Text='<%# Bind("Nationalität")%>' /><br />
Straße:
<asp:TextBox runat="server" ID="tbStraße" Text='<%# Bind("Straße")%>' /><br />
Hausnummer:
<asp:TextBox runat="server" ID="tbHausnummer" Text='<%# Bind("Hausnummer")%>' /><br />
PLZ:
<asp:TextBox runat="server" ID="tbPLZ" Text='<%# Bind("PLZ")%>' /><br />
Ort:
<asp:TextBox runat="server" ID="tbOrt" Text='<%# Bind("Ort")%>' /><br />
Land:
<asp:DropDownList AppendDataBoundItems="true" runat="server" ID="ddwnLand" Text='<%# Bind("Land")%>'>
</asp:DropDownList><br />
Mobil:
<asp:TextBox runat="server" ID="tbMobil" Text='<%# Bind("Mobil")%>' /><br />
Fax:
<asp:TextBox runat="server" ID="tbFax" Text='<%# Bind("Fax")%>' /><br />
Festnetz:
<asp:TextBox runat="server" ID="tbFestnetz" Text='<%# Bind("Festnetz")%>' /><br />
Email:
<asp:TextBox runat="server" ID="tbEmail" Text='<%# Bind("Email")%>' /><br />
Homepage:
<asp:TextBox runat="server" ID="tbBenutzerart" Text='<%# Bind("Homepage")%>' /><br />
Benutzerart:
<asp:DropDownList AppendDataBoundItems="true" runat="server" ID="ddwnBenutzerart" Text='<%# Bind("Benutzerart")%>'>
<asp:ListItem Text="Mitarbeiter" Value="Mitarbeiter"></asp:ListItem>
<asp:ListItem Text="Geschäftsführung" Value="Geschäftsführung"></asp:ListItem>
<asp:ListItem Text="Führungskraft" Value="Führungskraft"></asp:ListItem>
<asp:ListItem Text="Administrator" Value="Administrator"></asp:ListItem>
</asp:DropDownList><br />
Urlaubstage:
<asp:TextBox runat="server" ID="tbUrlaubstageInsgesamt" Text='<%# Bind("UrlaubstageInsgesamt")%>' /><br />
Benutzername:
<asp:TextBox runat="server" ID="tbBenutzername" Text='<%# Bind("Username")%>' /><br />
Passwort:
<asp:TextBox runat="server" ID="tbPasswort" Text='<%# Bind("UserPassword")%>' /><br />
<br />
<asp:Button ID="btnSpeichern" runat="server" CommandName="Insert" Text="Speichern" />
<asp:Button ID="btnAbbrechen" Text="Abbrechen" runat="server" OnClick="btnAbbrechen_Click" />
</InsertItemTemplate>
</asp:FormView>
<asp:SqlDataSource OnInserting="SqlDataSource1_Inserting" OnInserted="SqlDataSource1_Inserted" ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
InsertCommand="INSERT INTO Benutzer (GruppenID, Titel, Bezeichnung, Vorname, Nachname, Geburtsdatum, Geburtsort, Nationalität, Straße, Hausnummer, PLZ, Ort, Land, Mobil, Fax, Festnetz,
Email, Homepage, Benutzerart, UrlaubstageInsgesamt , UrlaubstageRest, Username, UserPassword)
VALUES (#GruppenID, #Titel, #Bezeichnung, #Vorname, #Nachname, #Geburtsdatum, #Geburtsort, #Nationalität, #Straße, #Hausnummer, #PLZ, #Ort, #Land, #Mobil, #Fax, #Festnetz,
#Email, #Homepage, #Benutzerart, #UrlaubstageInsgesamt , #UrlaubstageInsgesamt, #Username, #UserPassword)"></asp:SqlDataSource>
protected void SqlDataSource1_Inserting(object sender, SqlDataSourceCommandEventArgs e)
{
//Code to check textboxes goes here...
}
Have you tried:
TextBox tb = (TextBox)fvBenutzer.FindControl("yourtextboxid");
string text = tb.Text;
Edit:
You can stop the insert in the FormView ItemInserting event. For example:
protected void fvBenutzer_ItemInserting(object sender, FormViewInsertEventArgs e)
{
if(YourValidationCheck() == false)
e.Cancel = true;
}
Don't forget to add oniteminserting="fvBenutzer_ItemInserting" to the FormView tag.

Button refuses to work

I have a standard button which should call a method but it just refuses to work and I can't figure out why.
ASP code:
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button
ID="UploadButton" runat="server" onclick="UploadButton_Click" Text="Change Logo" />
Code behind:
protected void UploadButton_Click(object sender, EventArgs e)
{
PasswordLabel.Visible = true;
PasswordLabel.Text = "TEST Before";
Image_Inserting(this);
PasswordLabel.Text = "TEST After";
}
I just added the textbox methods to test it but it doesn't seem to be posting back (even when I remove Image_Inserting call). All other buttons work fine so I don't know why this one won't work.
EDIT: Whole page- Button code towards the bottom
<%# Page Title="" Language="C#" MasterPageFile="~/Standardmaster.Master" AutoEventWireup="true" CodeBehind="VendorAccount.aspx.cs" Inherits="PetShopParadise.Vendor_Pages.VendorAccount" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<style type="text/css">
.style10
{
color: #FF0000;
}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="mainContent" runat="server">
<h2>Account Details</h2>
<div id="RegistrationDiv">
<asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource1">
<EditItemTemplate>
Name:
<asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' />
<br />
Address:
<asp:TextBox ID="AddressTextBox" runat="server" Text='<%# Bind("Address") %>' />
<br />
Phone_Number:
<asp:TextBox ID="Phone_NumberTextBox" runat="server"
Text='<%# Bind("Phone_Number") %>' />
<br />
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True"
CommandName="Update" Text="Update" />
<asp:LinkButton ID="UpdateCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</EditItemTemplate>
<InsertItemTemplate>
Name:
<asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' />
<br />
Address:
<asp:TextBox ID="AddressTextBox" runat="server" Text='<%# Bind("Address") %>' />
<br />
Phone_Number:
<asp:TextBox ID="Phone_NumberTextBox" runat="server"
Text='<%# Bind("Phone_Number") %>' />
<br />
<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True"
CommandName="Insert" Text="Insert" />
<asp:LinkButton ID="InsertCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</InsertItemTemplate>
<ItemTemplate>
Name:
<asp:Label ID="NameLabel" runat="server" Text='<%# Bind("Name") %>' />
<br />
Address:
<asp:Label ID="AddressLabel" runat="server" Text='<%# Bind("Address") %>' />
<br />
Phone Number:
<asp:Label ID="Phone_NumberLabel" runat="server"
Text='<%# Bind("Phone_Number") %>' />
<br />
<asp:Button ID="Button3" runat="server" Text="Edit Details" CommandName="Edit" />
<br />
</ItemTemplate>
</asp:FormView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:PetShopParadiseConnectionString %>"
SelectCommand="SELECT [Name], [Address], [Phone_Number] FROM [Vendors] WHERE ([VendorID] = #VendorID)">
<SelectParameters>
<asp:SessionParameter Name="VendorID" SessionField="ID" Type="Decimal" />
</SelectParameters>
</asp:SqlDataSource>
<br />
<asp:Table ID="Table1" runat="server" style="text-align:left;">
<asp:TableRow ID="TableRow4" runat="server">
<asp:TableCell ID="TableCell7" runat="server">Password</asp:TableCell><asp:TableCell ID="TableCell8" runat="server">
<asp:TextBox ID="PasswordBox" TextMode="Password" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator
id="RequiredFieldValidator5"
runat="server"
ControlToValidate="PasswordBox"
Display="None"
Forecolor="Red"
ErrorMessage="Please enter a password." />
</asp:TableCell></asp:TableRow><asp:TableRow ID="TableRow5" runat="server">
<asp:TableCell ID="TableCell9" runat="server">Re-Enter Password</asp:TableCell><asp:TableCell ID="TableCell10" runat="server">
<asp:TextBox ID="PasswordCheckBox" TextMode="Password" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator
id="RequiredFieldValidator6"
runat="server"
ControlToValidate="PasswordCheckBox"
Display="None"
Forecolor="Red"
ErrorMessage="Please re-enter your password." />
</asp:TableCell></asp:TableRow></asp:Table><asp:Label
ID="PasswordLabel" runat="server" Text="Password" CssClass="style10"></asp:Label><br />
<asp:Button ID="PasswordButton"
runat="server" Text="Update Password" onclick="PasswordButton_Click" /><br />
<asp:SqlDataSource
ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:PetShopParadiseConnectionString %>"
onselecting="SqlDataSource2_Selecting" SelectCommand="SELECT * FROM Vendors"
UpdateCommand="UPDATE [Vendors] SET [Password]=#passwordhash WHERE ([VendorID] = #VendorID)" OnUpdating="Parameters_Updating">
<UpdateParameters>
<asp:Parameter Name="Password" />
<asp:SessionParameter name="VendorID" sessionfield="ID" />
</UpdateParameters>
</asp:SqlDataSource>
<br /><asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button
ID="UploadButton" runat="server" onclick="UploadButton_Click" Text="Change Logo" /></div></asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="bannerContent" runat="server">
</asp:Content>
My guess is that it is causing other (possibly hidden) validation to run. Make sure to set CausesValidation to false.
quote :
*I just added the textbox methods *
I guess our trying to update a Password textBox which you can't.
only by :
PasswordLabel .Attributes["value"] = "aaa";

how can i use datapager with datalist?

i have a datalist and a datapager but when i run my program it have error.
Control 'DataList1' does not implement IPageableItemContainer.
what is problem?
<asp:DataList ID="DataList1" runat="server" DataKeyField="id"
DataSourceID="SqlDataSource1">
<ItemTemplate>
id:
<asp:Label ID="idLabel" runat="server" Text='<%# Eval("id") %>' />
<br />
name:
<asp:Label ID="nameLabel" runat="server" Text='<%# Eval("name") %>' />
<br />
tedad:
<asp:Label ID="tedadLabel" runat="server" Text='<%# Eval("tedad") %>' />
<br />
group_id:
<asp:Label ID="group_idLabel" runat="server" Text='<%# Eval("group_id") %>' />
<br />
VDate:
<asp:Label ID="VDateLabel" runat="server" Text='<%# Eval("VDate") %>' />
<br />
KDate:
<asp:Label ID="KDateLabel" runat="server" Text='<%# Eval("KDate") %>' />
<br />
gheimat:
<asp:Label ID="gheimatLabel" runat="server" Text='<%# Eval("gheimat") %>' />
<br />
details:
<asp:Label ID="detailsLabel" runat="server" Text='<%# Eval("details") %>' />
<br />
imgae:
<asp:Label ID="imgaeLabel" runat="server" Text='<%# Eval("imgae") %>' />
<br />
"
SelectCommand="SELECT * FROM [Tbl_Kala_Group_No]">
<asp:DataPager ID="DataPager1" runat="server" PagedControlID = "DataList1" PageSize = "4" QueryStringField = "page" >
<Fields>
<asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True"
ShowLastPageButton="True" />
</Fields>
</asp:DataPager>
Datapager control does not support for DataList. it works with ListView.
so, Paging for DataList, you have create paging dynamically.
Just give in google : paging for Datalist, you will find lots of resource. Thank you.

Resources