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.
Related
Hi I'm having issues with my Website. I have a button which on it's onclick function i have a SQL function that selects certain data from a table in my database.
The information i get from the database is what i want my DataList source to be. But when i do a Databind, nothing happens, the page is blank.
I don't know if the problem is with my SQL Select Statement, I have put breakpoints just about everywhere but no joy.
This is my code below:
<asp:DataList ID="DataList1" runat="server" Visible ="false">
<ItemTemplate>
<asp:Label ID="TitleLabel" runat="server" Text='<%# Eval("Title") %>' />
<br />
<asp:Label ID="YearLabel" runat="server" Text='<%# Eval("Year") %>' />
<br />
<asp:Label ID="GenreLabel" runat="server" Text='<%# Eval("Genre") %>' />
<br />
<asp:Label ID="StarringLabel" runat="server"
Text='<%# Eval("Starring") %>' />
<br />
<asp:Label ID="RuntimeLabel" runat="server"
Text='<%# Eval("Runtime") %>' />
<br />
<asp:Label ID="DirectorLabel" runat="server"
Text='<%# Eval("Director") %>' />
<br />
<asp:Label ID="ProductionLabel" runat="server"
Text='<%# Eval("Production") %>' />
<br />
<asp:Label ID="CountryLabel" runat="server"
Text='<%# Eval("Country") %>' />
<br />
<asp:Label ID="LanguageLabel" runat="server"
Text='<%# Eval("Language") %>' />
<br />
<asp:Label ID="PlotLabel" runat="server" Text='<%# Eval("Plot") %>' />
<br />
<asp:Label ID="ReviewLabel" runat="server"
Text='<%# Eval("Review") %>' />
<br />
<asp:Label ID="RatingLabel" runat="server"
Text='<%# Eval("Rating") %>' />
<br />
<asp:Label ID="ItemLabel" runat="server" Text='<%# Eval("Item") %>' />
<br />
<br />
</ItemTemplate>
</asp:DataList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ConnectionStrings:
MetaCriticReviewConnectionString1 %>"
SelectCommand="SELECT [Title], [Year], [Genre], [Starring],
[Runtime], [Director], [Production], [Country],
[Language], [Plot],[Review], [Rating], [Item] FROM [Movie]">
</asp:SqlDataSource>
Code Behind:
public partial class TestPage : System.Web.UI.Page
{
databaseCode db = new databaseCode();
string lookupTitle;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Homelink_Click(object sender, EventArgs e)
{
}
protected void readmoreAvengers_Click(object sender, EventArgs e)
{
lookupTitle = "SELECT * FROM Movie WHERE [Item] ='" + 5 + "'";
SqlDataReader usersData = db.SQLDataReaderLookup(lookupTitle);
DataList1.DataSource = usersData;
DataList1.DataBind();
DataList1.Visible = true;
}
<asp:DataList ID="DataList1" runat="server" BackColor="#CCCCCC" DataSourceID="SqlDataSource1" Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Strikeout="False" Font-Underline="False" ForeColor="Black" style="margin-right: 260px" Width="720px">
<ItemTemplate>
<asp:Label ID="questionLabel" runat="server" Text='<%# Eval("question") %>' />
<br />
<asp:CheckBox ID="CheckBox1" runat="server" />
A:
<asp:Label ID="answer1Label" runat="server" Text='<%# Eval("answer1") %>' />
<br />
<asp:CheckBox ID="CheckBox2" runat="server" />
B:
<asp:Label ID="answer2Label" runat="server" Text='<%# Eval("answer2") %>' />
<br />
<asp:CheckBox ID="CheckBox3" runat="server" />
C:
<asp:Label ID="answer3Label" runat="server" Text='<%# Eval("answer3") %>' />
<br />
<asp:CheckBox ID="CheckBox4" runat="server" />
D:
<asp:Label ID="answer4Label" runat="server" Text='<%# Eval("answer4") %>' />
<br />
<br />
For example:
I want to insert answer1labl into column student_answer in database when: checkbox1.checked == true.
In the button click, you can do like,
protected void btnSave_Click(object sender, EventArgs e)
{
foreach (DataListItem item in DataList1.Items)
{
CheckBox cb = (CheckBox)item.FindControl("CheckBox1");
if (cb.Checked)
{
string text = ((Label)item.FindControl("answer1Label")).Text;
//save code
}
}
}
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>
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";
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.