Button refuses to work - asp.net

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";

Related

ASP.NET DropDownList in FormView

Been working on an ASP.NET form, and struggling with one particular part. I'm using a SqlDataSource with an Insert function that points to a stored proc, with a few input parameters. I have a FormView set up. I would like for one of the form's input fields to be a DropDownList whose options are populated from a different SqlDataSource. For reference, here is the formview:
<asp:FormView runat="server" id="FormView1" DataSourceID="SqlDataSource1" DefaultMode="Insert">
<EditItemTemplate>
refund_ach:
<asp:CheckBox Checked='<%# Bind("ach") %>' runat="server" id="refund_achCheckBox" />
<br />
refund_dba_name:
<asp:TextBox Text='<%# Bind("dbaname") %>' runat="server" id="refund_dba_nameTextBox" />
<br />
refund_mid:
<asp:TextBox Text='<%# Bind("mid") %>' runat="server" id="refund_midTextBox" />
<br />
refund_description:
<asp:TextBox Text='<%# Bind("description") %>' runat="server" id="refund_descriptionTextBox" />
<br />
refund_amount:
<asp:TextBox Text='<%# Bind("amount") %>' runat="server" id="refund_amountTextBox" />
<br />
refund_type:
<asp:TextBox Text='<%# Bind("type") %>' runat="server" id="refund_typeTextBox" />
<br />
<asp:LinkButton runat="server" Text="Update" CommandName="Update" id="UpdateButton" CausesValidation="True" />
<asp:LinkButton runat="server" Text="Cancel" CommandName="Cancel" id="UpdateCancelButton" CausesValidation="False" />
</EditItemTemplate>
<InsertItemTemplate>
<asp:Table runat="server" id="Table1">
<asp:TableRow>
<asp:TableCell>ACH?:
</asp:TableCell>
<asp:TableCell><asp:CheckBox Checked='<%# Bind("ach") %>' runat="server" id="refund_achCheckBox" />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>DBA Name:
</asp:TableCell>
<asp:TableCell><asp:TextBox Text='<%# Bind("dbaname") %>' runat="server" id="refund_dba_nameTextBox" />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>MID:
</asp:TableCell>
<asp:TableCell><asp:TextBox Text='<%# Bind("mid") %>' runat="server" id="refund_midTextBox" />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>Description:
</asp:TableCell>
<asp:TableCell><asp:TextBox Text='<%# Bind("description") %>' runat="server" id="refund_descriptionTextBox" />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>Amount:
</asp:TableCell>
<asp:TableCell><asp:TextBox Text='<%# Bind("amount") %>' runat="server" id="refund_amountTextBox" />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>Type:
</asp:TableCell>
<asp:TableCell><asp:DropDownList DataSourceID="SqlDataSource2" SelectedValue='<%# Bind("type") %>' DataTextField="Reason" DataValueField="ID" runat="server" id="refund_typeTextBox" />
</asp:TableCell>
</asp:TableRow>
</asp:Table>
<asp:LinkButton runat="server" Text="Insert" CommandName="Insert" id="InsertButton" CausesValidation="True" />
<asp:LinkButton runat="server" Text="Cancel" CommandName="Cancel" id="InsertCancelButton" CausesValidation="False" />
</InsertItemTemplate>
<ItemTemplate>
refund_ach:
<asp:CheckBox Checked='<%# Bind("ach") %>' runat="server" id="refund_achCheckBox" Enabled="false" />
<br />
refund_dba_name:
<asp:Label Text='<%# Bind("dbaname") %>' runat="server" id="refund_dba_nameLabel" />
<br />
refund_mid:
<asp:Label Text='<%# Bind("mid") %>' runat="server" id="refund_midLabel" />
<br />
refund_description:
<asp:Label Text='<%# Bind("description") %>' runat="server" id="refund_descriptionLabel" />
<br />
refund_amount:
<asp:Label Text='<%# Bind("amount") %>' runat="server" id="refund_amountLabel" />
<br />
refund_type:
<asp:Label Text='<%# Bind("type") %>' runat="server" id="refund_typeLabel" />
<br />
</ItemTemplate>
</asp:FormView>
And here is the SqlDataSource:
<asp:SqlDataSource runat="server" id="SqlDataSource1" ProviderName="System.Data.SqlClient" ConnectionString="Data Source=myserver;Initial Catalog=mydatabase;Persist Security Info=True;User ID=mysvcaccount;Password=NOPE!;" SelectCommand="SELECT [refund_ach], [refund_dba_name], [refund_mid], [refund_description], [refund_amount], [refund_type] FROM [refund]" InsertCommand="EXEC usp_refund_insert #user, #ach, #dbaname, #mid, #description, #amount, #type">
<InsertParameters>
<asp:formparameter FormField="refund_achCheckBox" Name="ach" Type="Boolean" />
<asp:formparameter FormField="refund_amountTextBox" Name="amount" Type="Decimal" />
<asp:formparameter FormField="refund_dba_nameTextBox" Name="dbaname" Type="String" />
<asp:formparameter FormField="refund_descriptionTextBox" Name="description" Type="String" />
<asp:formparameter FormField="refund_midTextBox" Name="mid" Type="String" />
<asp:formparameter FormField="refund_typeTextBox" Name="type" Type="Int32" />
<asp:parameter DefaultValue="dfsdf" Name="user" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
The data populates in the DDL just fine (from another SqlDataSource). All of the desired options come up. But when submitting the form, I get an error. I removed the DDL and hard-coded a value to that parameter, and it executed fine. I spent the last couple hours scouring the internet for a solution, finding tons, trying them, and not having any luck. I'm a DBA by trade, so .NET is not my forté, but it really doesn't seem like it should be this difficult to get a DDL to work like this.
WOW. After being very frustrated, I decided to start from scratch and give it another go, just to make sure I didn't miss anything. I built everything EXACTLY the same, MINUS all of the table elements... and it worked perfectly. I added the table elements back, stopped working. Removed them again: works.
No idea why, perhaps an .NET-proficient person can explain why, but it definitely solved my problem.

Ajax for asp.net form view

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>

How can i add a event handler to a customized button inside listview?

This is my markup
<%# Page Title="Daily Expenses" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Daily Expenses.aspx.cs" Inherits="Daily_Expenses" %>
function calendar_datechange() {
__doPostBack('txtCalendar', 'txtCalendar_TextChanged');
}
function Calculate_Difference() {
alert("Hello");
}
</script>
<asp:ToolkitScriptManager ID="AjaxScript" runat="server"></asp:ToolkitScriptManager>
<asp:TextBox ID="txtCalendar" runat="server"
ontextchanged="txtCalendar_TextChanged"></asp:TextBox>
<%--<asp:PopupControlExtender ID="txtCalendar_PopupControlExtender" runat="server"
DynamicServicePath="" Enabled="True" ExtenderControlID="" PopupControlID="Panel1"
TargetControlID="txtCalendar">
</asp:PopupControlExtender>
<asp:Panel ID="Panel1" runat="server">
<h2>Hello There</h2>
</asp:Panel>--%>
<asp:CalendarExtender ID="CalendarControl" runat="server" OnClientDateSelectionChanged="calendar_datechange" TargetControlID="txtCalendar" PopupButtonID="CalendarButton">
</asp:CalendarExtender>
<%--<ajaxToolkit:CalendarExtender ID="CalendarControl" runat="server" OnClientDateSelectionChanged="calendar_datechange" TargetControlID="txtCalendar" PopupButtonID="CalendarButton"></ajaxToolkit:CalendarExtender>--%>
<asp:Button ID="CalendarButton" runat="server" Text="Calendar" />
<br />
<br />
<br />
<asp:ListView ID="ListView1" runat="server" DataKeyNames="SNO"
DataSourceID="SqlDataSource1" InsertItemPosition="LastItem">
<AlternatingItemTemplate>
<li style="background-color: #FFF8DC;">SNO:
<asp:Label ID="SNOLabel" runat="server" Text='<%# Eval("SNO") %>' />
<br />
Taxinreal:
<asp:Label ID="TaxinrealLabel" runat="server" Text='<%# Eval("Taxinreal") %>' />
<br />
Taxinpercent:
<asp:Label ID="TaxinpercentLabel" runat="server"
Text='<%# Eval("Taxinpercent") %>' />
<br />
Amount:
<asp:Label ID="AmountLabel" runat="server" Text='<%# Eval("Amount") %>' />
<br />
NetAmount:
<asp:Label ID="NetAmountLabel" runat="server" Text='<%# Eval("NetAmount") %>' />
<br />
DateTakenPlace:
<asp:Label ID="DateTakenPlaceLabel" runat="server"
Text='<%# Eval("DateTakenPlace") %>' />
<br />
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
<asp:Button ID="DeleteButton" runat="server" CommandName="Delete"
Text="Delete" />
<asp:Button ID="Differencebutton" runat="server" Text="Calculate Difference" OnClientClick="Calculate_Difference" />
</li>
</AlternatingItemTemplate>
<EditItemTemplate>
<li style="background-color: #008A8C;color: #FFFFFF;">SNO:
<asp:Label ID="SNOLabel1" runat="server" Text='<%# Eval("SNO") %>' />
<br />
Taxinreal:
<asp:TextBox ID="TaxinrealTextBox" runat="server"
Text='<%# Bind("Taxinreal") %>' />
<br />
Taxinpercent:
<asp:TextBox ID="TaxinpercentTextBox" runat="server"
Text='<%# Bind("Taxinpercent") %>' />
<br />
Amount:
<asp:TextBox ID="AmountTextBox" runat="server" Text='<%# Bind("Amount") %>' />
<br />
NetAmount:
<asp:TextBox ID="NetAmountTextBox" runat="server"
Text='<%# Bind("NetAmount") %>' />
<br />
DateTakenPlace:
<asp:TextBox ID="DateTakenPlaceTextBox" runat="server"
Text='<%# Bind("DateTakenPlace") %>' />
<br />
<asp:Button ID="UpdateButton" runat="server" CommandName="Update"
Text="Update" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel"
Text="Cancel" />
<asp:Button ID="Differencebutton" runat="server" CommandName="Difference" OnClientClick="Calculate_Difference" Text="Calculate Difference" />
</li>
</EditItemTemplate>
<EmptyDataTemplate>
No data was returned.
</EmptyDataTemplate>
<InsertItemTemplate>
<li style="">Taxinreal:
<asp:TextBox ID="TaxinrealTextBox" runat="server"
Text='<%# Bind("Taxinreal") %>' />
<br />
Taxinpercent:
<asp:TextBox ID="TaxinpercentTextBox" runat="server"
Text='<%# Bind("Taxinpercent") %>' />
<br />
Amount:
<asp:TextBox ID="AmountTextBox" runat="server" Text='<%# Bind("Amount") %>' />
<br />
NetAmount:
<asp:TextBox ID="NetAmountTextBox" runat="server"
Text='<%# Bind("NetAmount") %>' />
<br />
DateTakenPlace:
<asp:TextBox ID="DateTakenPlaceTextBox" runat="server"
Text='<%# Bind("DateTakenPlace") %>' />
<br />
<asp:Button ID="InsertButton" runat="server" CommandName="Insert"
Text="Insert" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel"
Text="Clear" />
<asp:Button ID="Differencebutton" runat="server" CommandName="Difference" OnClientClick="Calculate_Difference" Text="Calculate Difference" />
</li>
</InsertItemTemplate>
<ItemSeparatorTemplate>
<br />
</ItemSeparatorTemplate>
<ItemTemplate>
<li style="background-color: #DCDCDC;color: #000000;">SNO:
<asp:Label ID="SNOLabel" runat="server" Text='<%# Eval("SNO") %>' />
<br />
Taxinreal:
<asp:Label ID="TaxinrealLabel" runat="server" Text='<%# Eval("Taxinreal") %>' />
<br />
Taxinpercent:
<asp:Label ID="TaxinpercentLabel" runat="server"
Text='<%# Eval("Taxinpercent") %>' />
<br />
Amount:
<asp:Label ID="AmountLabel" runat="server" Text='<%# Eval("Amount") %>' />
<br />
NetAmount:
<asp:Label ID="NetAmountLabel" runat="server" Text='<%# Eval("NetAmount") %>' />
<br />
DateTakenPlace:
<asp:Label ID="DateTakenPlaceLabel" runat="server"
Text='<%# Eval("DateTakenPlace") %>' />
<br />
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
<asp:Button ID="DeleteButton" runat="server" CommandName="Delete"
Text="Delete" />
<asp:Button ID="Differencebutton" runat="server" CommandName="Difference" OnClientClick="Calculate_Difference" Text="Calculate Difference" />
</li>
</ItemTemplate>
<LayoutTemplate>
<ul ID="itemPlaceholderContainer" runat="server"
style="font-family: Verdana, Arial, Helvetica, sans-serif;">
<li runat="server" id="itemPlaceholder" />
</ul>
<div style="text-align: center;background-color: #CCCCCC;font-family: Verdana, Arial, Helvetica, sans-serif;color: #000000;">
<asp:DataPager ID="DataPager1" runat="server">
<Fields>
<asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True"
ShowLastPageButton="True" />
</Fields>
</asp:DataPager>
</div>
</LayoutTemplate>
<SelectedItemTemplate>
<li style="background-color: #008A8C;font-weight: bold;color: #FFFFFF;">SNO:
<asp:Label ID="SNOLabel" runat="server" Text='<%# Eval("SNO") %>' />
<br />
Taxinreal:
<asp:Label ID="TaxinrealLabel" runat="server" Text='<%# Eval("Taxinreal") %>' />
<br />
Taxinpercent:
<asp:Label ID="TaxinpercentLabel" runat="server"
Text='<%# Eval("Taxinpercent") %>' />
<br />
Amount:
<asp:Label ID="AmountLabel" runat="server" Text='<%# Eval("Amount") %>' />
<br />
NetAmount:
<asp:Label ID="NetAmountLabel" runat="server" Text='<%# Eval("NetAmount") %>' />
<br />
DateTakenPlace:
<asp:Label ID="DateTakenPlaceLabel" runat="server"
Text='<%# Eval("DateTakenPlace") %>' />
<br />
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
<asp:Button ID="DeleteButton" runat="server" CommandName="Delete"
Text="Delete" />
<asp:Button ID="Differencebutton" runat="server" CommandName="Difference" OnClientClick="Calculate_Difference" Text="Calculate Difference" />
</li>
</SelectedItemTemplate>
</asp:ListView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnString %>"
DeleteCommand="DELETE FROM [tblexpenses] WHERE [SNO] = #SNO"
InsertCommand="INSERT INTO [tblexpenses] ([Taxinreal], [Taxinpercent], [Amount], [NetAmount], [DateTakenPlace]) VALUES (#Taxinreal, #Taxinpercent, #Amount, #NetAmount, #DateTakenPlace)"
SelectCommand="SELECT * FROM [tblexpenses] WHERE ([DateTakenPlace] = #DateTakenPlace2)"
UpdateCommand="UPDATE [tblexpenses] SET [Taxinreal] = #Taxinreal, [Taxinpercent] = #Taxinpercent, [Amount] = #Amount, [NetAmount] = #NetAmount, [DateTakenPlace] = #DateTakenPlace WHERE [SNO] = #SNO">
<DeleteParameters>
<asp:Parameter Name="SNO" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="Taxinreal" Type="Double" />
<asp:Parameter Name="Taxinpercent" Type="Decimal" />
<asp:Parameter Name="Amount" Type="Double" />
<asp:Parameter Name="NetAmount" Type="Int32"/>
<asp:Parameter DbType="Date" Name="DateTakenPlace" />
</InsertParameters>
<SelectParameters>
<asp:ControlParameter ControlID="txtCalendar" DbType="Date"
Name="DateTakenPlace2" PropertyName="Text" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="Taxinreal" Type="Double" />
<asp:Parameter Name="Taxinpercent" Type="Decimal" />
<asp:Parameter Name="Amount" Type="Double" />
<asp:Parameter Name="NetAmount" Type="Int32" />
<asp:Parameter DbType="Date" Name="DateTakenPlace" />
<asp:Parameter Name="SNO" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
<br />
<br />
<br />
<br />
<br />
<br />
I have a table tblexpense in my database. I have columns named Taxinreal , Taxinpercent,*Amount* NetAmount.*NetAmount* is computed column which is equal to*(Amount-Taxinreal-Taxinpercent)* Now what i want is at runtime in my aspx page the user must be able to insert amount,tax,taxinpercentage and according to the value supplied by user NetAmount must be calculated(Netamount=Amount-Tax-Taxpercentage) at runtime and inserted into the database.For this purpose i have a differencebutton which should perform the required mathematical operation. The problem i am having is i am using a listview. Now adding a new button is simple but how can i perform required mathematical operation in the click event of difference button so that when the listview is in update mode the user can change values of taxinreal ,taxinpercent and obtain the result at runtime and the result be updated in database ??? I need solution urgently(P.S. I need to use Listview only).
You want to use OnItemCommand of ListView.
Here is a sample.
You need to insert/update to database (using either ADO.Net, entity framework or linq-to-sql) in code behind if you want to perform calculation.

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.

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