Printing data upon saving - c#

I am using asp.net(C#) web forms. I have complaints.aspx page which takes several inputs from users and then saves them upon clicking SAVE button. It's working perfectly but now I am stuck with one problem, I want to make a printout of the submitted record upon clicking the save button. It should be printed from the local printer but I couldn't find any solutions for it.
.aspx code:
<%# Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="frmStaffMembers.aspx.cs" Inherits="frmStaffMembers" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<script type="text/javascript">
$(document).ready(function () {
$("#btnUpdate").hide();
$("#btnDelete").hide();
$("#btnCancel").hide();
$("#lblSelectedID-Span").hide();
$("#txtSelectedID-Span").hide();
var showHide = $("#HiddenFieldShowHideButtons").val();
if (showHide == "True") {
$("#btnUpdate").show();
$("#btnDelete").show();
$("#btnCancel").show();
$("#lblSelectedID-Span").show();
$("#txtSelectedID-Span").show();
$("#buttonSearch").hide();
$("#Save-Span").hide();
$("#HiddenFieldShowHideButtons").val("False");
}
$("#btnUpdate").click(function () {
$("#ConfirmMsg").text("Are you sure to update this record?");
$("#Delete-Span").hide();
$("#lblSelectedID-Span").hide();
$("#txtSelectedID-Span").hide();
$("#Save-Span").show();
$("#buttonSearch").show();
$("#Update-Span").show();
$("#btnUpdate").hide();
$("#btnDelete").hide();
$("#btnCancel").hide();
$("#ModalConfirmAction").modal({ show: true })
});
$("#btnDelete").click(function () {
$("#ConfirmMsg").text("Are you sure to delete this record?");
$("#Update-Span").hide();
$("#lblSelectedID-Span").hide();
$("#txtSelectedID-Span").hide();
$("#Delete-Span").show();
$("#Save-Span").show();
$("#buttonSearch").show();
$("#btnDelete").hide();
$("#btnUpdate").hide();
$("#btnCancel").hide();
$("#ModalConfirmAction").modal({ show: true })
});
$("#btnCancel").click(function () {
$("#btnUpdate").hide();
$("#btnDelete").hide();
$("#btnCancel").hide();
$("#lblSelectedID-Span").hide();
$("#txtSelectedID-Span").hide();
$("#buttonSearch").show();
$("#Save-Span").show();
ClearTextBoxes();
});
});
function ClearTextBoxes() {
$("input[type=text]").each(function () {
$(this).val("");
});
}
</script>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div class="widget">
<div class="widget-header">
<div class="title">
Staff Members
<span id="sectionDetails" class="mini-title" runat="server"> Enter/Edit record </span>
</div> <!-- widget title-->
</div> <!-- widget header -->
<div class="widget-body">
<div class="row-fluid">
<!-- cons start -->
<div class="shortcut-group">
<asp:HiddenField ID="HiddenFieldSetMessage" runat="server"
ClientIDMode="Static"/>
<asp:HiddenField ID="HiddenFieldShowMessage" runat="server"
ClientIDMode="Static"/>
<asp:HiddenField ID="HiddenFieldShowHideButtons" runat="server"
ClientIDMode="Static" />
<span id="lblSelectedID-Span"><label id="lblSelectedID" runat="server">Selected ID</label></span>
<span id="txtSelectedID-Span"><asp:TextBox ID="txtSelectedID" runat="server" ReadOnly="True"
CssClass="textField_width"></asp:TextBox></span>
<label>Member Name</label>
<asp:TextBox ID="txtMemberName" runat="server" ValidationGroup="GroupCompanies"
CssClass="textField_width"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="txtMemberName" ErrorMessage="Member Name is Required"
ForeColor="Red" ValidationGroup="grpValidationTextboxes">Member Name is Required
</asp:RequiredFieldValidator>
<br />
<label>Member CNIC</label>
<asp:TextBox ID="txtMemberCNIC" runat="server" CssClass="textField_width"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="txtMemberCNIC" ErrorMessage="Member CNIC is Required"
ForeColor="Red" ValidationGroup="grpValidationTextboxes">Member CNIC is Required
</asp:RequiredFieldValidator>
<br />
<label>ContactNo</label>
<asp:TextBox ID="txtContactNo" runat="server" CssClass="textField_width"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
ControlToValidate="txtContactNo" ErrorMessage="Contact No is Required"
ForeColor="Red" ValidationGroup="grpValidationTextboxes">Conatact No is Required
</asp:RequiredFieldValidator>
<br />
<label>Head's Designation</label>
<asp:DropDownList ID="ddlHeadDesignations" runat="server" width="220px">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server"
ControlToValidate="ddlHeadDesignations" InitialValue="0" ErrorMessage="Selection is Required"
ForeColor="Red" ValidationGroup="grpValidationTextboxes">Selection is Required
</asp:RequiredFieldValidator>
<br />
<label>Is Morning?</label>
<asp:DropDownList ID="ddlMorningEvening" runat="server" width="220px">
<asp:ListItem Value="-1" Text="-Select-"></asp:ListItem>
<asp:ListItem Value="1" Text="Yes"></asp:ListItem>
<asp:ListItem Value="0" Text="No"></asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"
ControlToValidate="ddlMorningEvening" InitialValue="-1" ErrorMessage="Selection is Required"
ForeColor="Red" ValidationGroup="grpValidationTextboxes">Selection is Required
</asp:RequiredFieldValidator>
<br />
<br/>
<span id="Save-Span">
<asp:Button ID="btnSave" CssClass="btn btn-success" runat="server" Text="Save"
onclick="btnSave_Click" ValidationGroup="grpValidationTextboxes" ClientIDMode="Static" />
</span>
<input type="button" id="btnUpdate" class="btn btn-success" value="Update"/>&nbsp
<input type="button" id="btnDelete" class="btn btn-danger" value="Delete"/>&nbsp
<input type="button" id="btnCancel" class="btn btn-success" value="Cancel" />
Search Records
</div> <!-- shourtcut group">
<!-- cons end -->
</div> <!-- row fluid -->
</div> <!-- widget body-->
</div> <!-- widget-->
<div class="clearfix"></div>
<!-- Modal -->
<div id="myModal" style="width:700px important;" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel">Search Records</h3>
</div>
<div class="modal-body">
<p>Please enter staff member's name to search relevant record/Press search button with empty field to view all records</p>
<label>Staff Member</label>
<asp:TextBox ID="txtStaffMemberNamePopUp" runat="server"></asp:TextBox>
<asp:Button ID="btnSearchPopup" CssClass="btn btn-success pad_mar" runat="server" Text="Search"
onclick="btnSearchPopup_Click" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnSearchPopup" EventName = "Click"/>
<asp:AsyncPostBackTrigger ControlID = "gridviewStaffMembers" EventName="PageIndexChanging" />
<asp:AsyncPostBackTrigger ControlID="gridviewStaffMembers"
EventName="SelectedIndexChanging" />
</Triggers>
<ContentTemplate>
<asp:Label ID="lblMsgPopUp" runat="server"
Text="No records found for the specified criteria" Visible="False"
ForeColor="Red"></asp:Label>
<asp:GridView ID="gridviewStaffMembers" CellPadding="20" runat="server"
AutoGenerateSelectButton="True" Visible="False"
GridLines="None"
AllowPaging="True"
CssClass="mGrid"
PagerStyle-CssClass="pgr"
AlternatingRowStyle-CssClass="alt"
OnPageIndexChanging="gridviewStaffMembers_PageIndexChanging" >
<AlternatingRowStyle CssClass="alt"></AlternatingRowStyle>
<FooterStyle BorderWidth="0px" />
<PagerStyle CssClass="pgr"></PagerStyle>
<RowStyle BorderWidth="0px" CssClass="row" Wrap="True" />
<SelectedRowStyle CssClass="selected-row" ForeColor="White" />
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
</div>
<div class="modal-footer">
<asp:Button ID="btnClose" runat="server" Text="Close" CssClass="btn btn-success" data-dismiss="modal" aria-hidden="true" />
<asp:Button ID="btnEdit" CssClass="btn btn-success" runat="server" Text="Edit" onclick="btnEdit_Click"/>
</div>
</div>
<!-- this is confirmation modal-->
<div id="ModalConfirmAction" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="H1">Confirmation</h3>
</div>
<div class="modal-body">
<p id="ConfirmMsg"></p>
</div>
<div class="modal-footer">
<span id="Delete-Span">
<asp:Button ID="btnDeletePopUp" CssClass="btn btn-danger" runat="server"
Text="Delete" onclick="btnDeletePopUp_Click" />
</span>
<span id="Update-Span">
<asp:Button ID="btnUpdatePopUp" CssClass="btn btn-success" runat="server" Text="Update"
onclick="btnUpdatePopUp_Click" />
</span>
<asp:Button ID="btnClosePopup" runat="server" Text="Cancel"
CssClass="btn btn-success" onclick="btnClosePopup_Click"/>
</div>
</div>
</asp:Content>
.cs code:
protected void btnSave_Click(object sender, EventArgs e)
{
try
{
short HeadDesignationID = Convert.ToInt16(ddlHeadDesignations.SelectedValue);
short IsMorning = Convert.ToInt16(ddlMorningEvening.SelectedValue);
StaffMembersBizz StaffMembersBizz = new StaffMembersBizz(txtMemberName.Text, txtMemberCNIC.Text,
txtContactNo.Text, HeadDesignationID, IsMorning);
ManageStaffMembers mngStaffMembers = new ManageStaffMembers();
bool Result = mngStaffMembers.Insert(StaffMembersBizz);
if (Result == true)
{
HiddenFieldSetMessage.Value = "Saved";
HiddenFieldShowMessage.Value = "True";
Clear(txtMemberName, txtMemberCNIC, txtContactNo);
}
else
{
HiddenFieldSetMessage.Value = "RecordAlreadyExists";
HiddenFieldShowMessage.Value = "True";
}
}
catch (Exception)
{
HiddenFieldSetMessage.Value = "NotSaved";
HiddenFieldShowMessage.Value = "True";
}
}

I assume after you save, there is some sort of confirm page?
If so in your Save event, you could add the following code which will bring up the print prompt for the confirmation page automatically. You can't make the client print on your own because that is controlled on their end but you can make the print dialog appear.
Add this server side code to the end of you Save event:
ClientScript.RegisterStartupScript(this.GetType(), "FormLoading", "window.print();", true);
Make sure that page that is served up has the print data that you need and is formatted correctly. You can customize the css to apply a print only style as well.

Related

Is there a way to resolve a problem of "SelectedIndex which is invalid" in c#

I am a first year student and I am currently developing a web application base on an ecommerce website. I recently encountered a problem which I cannot resolve while spending weeks on it.
The problem is when I update a product on the app I get an error this says crashes my application.
Here is the Problem.
Exception Details: System.ArgumentOutOfRangeException: 'ddlcat' has a SelectedIndex which is invalid because it does not exist in the list of items.
Parameter name: value
and here my code for the frontend and backend.
frontend:
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="maincontent" runat="server">
<div class="form-horizontal">
<h4>Manage product</h4>
<hr />
<div class="col-md-8">
<asp:TextBox runat="server" ID="txtProductid" Visible="false"
CssClass="form-control" />
</div>
<div class="form-group row justify-content-center">
<asp:Label runat="server" CssClass="col-md-2 col-form-label">Select
a Category</asp:Label>
<div class="col-md-8">
<asp:DropDownList ID="ddlcat" runat="server"
CssClass="form-control">
</asp:DropDownList>
</div>
</div>
<div class="form-group row justify-content-center">
<asp:Label runat="server"
CssClass="col-md-2 col-form-label"></asp:Label>
</div>
<div class="form-group row justify-content-center">
<asp:Label runat="server" CssClass="col-md-2 col-form-label">Product name</asp:Label>
<div class="col-md-8">
<asp:TextBox runat="server" ID="txtPname"
CssClass="form-control" />
</div>
</div>
<div class="form-group row justify-content-center">
<asp:Label runat="server"
CssClass="col-md-2 col-form-label">Product Brand</asp:Label>
<div class="col-md-8">
<asp:TextBox runat="server" ID="txtPbrand"
CssClass="form-control" />
</div>
</div>
<div class="form-group row justify-content-center">
<asp:Label runat="server" CssClass="col-md-2 col-form-label">Product price</asp:Label>
<div class="col-md-8">
<asp:TextBox runat="server" ID="txtprice"
CssClass="form-control" />
</div>
</div>
<div class="form-group row justify-content-center">
<asp:Label runat="server"
CssClass="col-md-2 col-form-label">Product Description</asp:Label>
<div class="col-md-8">
<asp:TextBox runat="server" ID="txtPdesc" TextMode="Multiline"
CssClass="form-control" />
</div>
</div>
<div class="form-group row justify-content-center">
<asp:Label runat="server"
CssClass="col-md-2 col-form-label">Product image</asp:Label>
<div class="col-md-8">
<asp:FileUpload ID="fuimage" runat="server" CssClass="" />
<asp:Image ID="Image1" runat="server" Visible="false" Width="75"
Height="100" />
</div>
</div>
<div class="form-group row justify-content-center">
<asp:Label runat="server"
CssClass="col-md-2 col-form-label"></asp:Label>
<div class="col-md-8">
<div class="form-check-inline">
<asp:CheckBox runat="server" ID="chkstatus"
CssClass="form-check-input" />
<asp:Label runat="server"
CssClass="form-check-label">Status</asp:Label>
</div>
</div>
</div>
<div class="form-group row justify-content-center">
<div class="offset-md-2 col-md-8">
<asp:Button runat="server" ID="btnupdate" OnClick="btnupdate_Click" Text="Update Product"
Visible="false" CssClass="btn btn-block btn-outline-primary" />
<asp:Button runat="server" ID="btndelete" OnClick="btndelete_Click" Text="Delete Product"
OnClientClick="return confirm ('Are you sure you want to delete?')"
Visible="false" CssClass="btn btn-block btn-outline-primary" />
<asp:Button runat="server" ID="btncancel" OnClick="btncancel_Click" Text="Cancel"
Visible="false" CssClass="btn btn-block btn-outline-primary" />
<asp:Label ID="lblMsg" runat="server" Text=""></asp:Label>
</div>
</div>
</div>
<hr />
<asp:GridView ID="gvs" AutoGenerateColumns="false"
DataKeyNames="P_id"
OnSelectedIndexChanged="gvs_SelectedIndexChanged" ClientIDMode="Static"
Width="800" runat="server">
<HeaderStyle BackColor="#eeeeee" ForeColor="White" Font-Bold="true"
Height="30" />
<AlternatingRowStyle BackColor="#f5f5f5" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lbtnSelect" runat="server"
CssClass="btn btn-outline-info" CommandName="Select" Text="Select" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Movie Name">
<ItemTemplate>
<!-- display the movie name -->
<asp:Label ID="lblproductname" Text='<%#Eval("P_name")%>'
runat="server" />
</ItemTemplate>
</asp:TemplateField>
<%-- add an imagefield here to display the poster--%>
</Columns>
</asp:GridView>
</asp:Content>
Backend
protected void gvs_SelectedIndexChanged(object sender, EventArgs e) <----------- theproblem is found here --------------------->
{
lblMsg.Text = "";
Image1.Visible = true;
txtProductid.Text =
(gvs.DataKeys[gvs.SelectedIndex].Value.ToString());
txtPname.Text =
((Label)gvs.SelectedRow.FindControl("lblproductname")).Text;
SqlConnection con = new SqlConnection(_conString);
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
//create the movieid parameter
cmd.Parameters.AddWithValue("#pid", txtProductid.Text);
//assign the parameter to the sql statement
cmd.CommandText = "SELECT * FROM tblProduct where P_id = #pid";
SqlDataReader dr;
con.Open();
dr = cmd.ExecuteReader();
while (dr.Read())
{
//retrieving FIELD values and assign the form controls
ddlcat.SelectedIndex = Convert.ToInt32(dr["Category_cat_id"]);
txtPbrand.Text = dr["P_brand"].ToString();
txtPdesc.Text = dr["P_description"].ToString();
txtprice.Text = dr["P_cost"].ToString();
chkstatus.Checked = (Boolean)dr["P_status"];
Image1.ImageUrl = "../image/" + dr["P_image"].ToString();
}
con.Close();
btnupdate.Visible = true;
btndelete.Visible = true;
btncancel.Visible = true;
}
private void ResetAll()
{
btncancel.Visible = false;
btndelete.Visible = false;
btnupdate.Visible = false;
ddlcat.SelectedIndex = 0;
txtPname.Text = "";
txtprice.Text = "";
txtPbrand.Text = "";
txtPdesc.Text = "";
chkstatus.Checked = false;
Image1.ImageUrl = "";
}
Simply if you guys can take a look about it, this would help me greatly.
Thanks in advance

I need to change the text of NextButton using RadWizard

I'm trying to change the text of next button in radwizard from the code behind, can some one please help me?
I have four steps and I want to be able to change the text of the button next when I'm in a specific step of the wizard, is this possible
<telerik:RadWizard ID="rwzPurchase" runat="server" Height="510px" Width="100%" DisplayProgressBar="false" OnNextButtonClick="rwzPurchase_NextButtonClick1" DisplayNavigationButtons="true" DisplayCancelButton="true">
<WizardSteps>
<%-- Confirmation --%>
<telerik:RadWizardStep Title="Confirmation">
<div class="row-fluid">
<div class="control-group-header margin-bottom-10">
<asp:label class="label-greentheme label label-inline-border" ID="LBTitle" runat="server">RP Specific Options</asp:label><br />
</div>
<br />
</div>
<div style="text-align:left">
<asp:Label ID="LBMessage" runat="server" Font-Size="Large" CssClass="message" />
</div>
</telerik:RadWizardStep>
<%-- Grower Information --%>
<telerik:RadWizardStep Title="Grower Information">
<uc1:GrowerInfo runat="server" ID="GrowerInfo" />
</telerik:RadWizardStep>
<%-- E-Signature --%>
<telerik:RadWizardStep Title="E-Signature">
<uc1:eSigControl runat="server" ID="eSigControl" />
</telerik:RadWizardStep>
<%-- Finish --%>
<telerik:RadWizardStep Title="Finish">
<div class="container">
<div class="row-fluid">
<div class="control-group-header margin-bottom-10">
<asp:Label class="label-greentheme label label-inline-border" ID="LBSuccessTitle" runat="server" /><br />
</div>
<br />
<asp:Label ID="LBSuccessText" runat="server" Font-Size="Large"/>
</div>
</div>
</telerik:RadWizardStep>
</WizardSteps>
</telerik:RadWizard>
c#
protected void rwzPurchase_NextButtonClick1(object sender, WizardEventArgs e)
{
if (rwzPurchase.ActiveStep.Title == "Grower Information")
{
//Here is where I want to change the text of button if we are in this specific step
RadButton button = (RadButton)sender;
button.Text = "test";
this.rwzPurchase.CommandArea.CommandElements.Add(button);
}
}

Alertify.JS and ASP.NET: Call Javascript from Code-behind

I have a question.
I am now using the current version of Alertify.js found here. I wanted to integrate it with my ASP.NET application. When I click the Save button from my Modal Dialog, it proceeds to the code-behind without problems. I've tried "alert("Test");" inside the ScriptManager.RegisterClientScriptBlock and it does render.
Now when I try to use my custom function located in one of the files I've added, it seems the script does not respond, i.e. Alertify does not show.
Here is the JavaScript code from my custom JS file, my C# Code behind for that Save button, and the ASP.NET Page.
JS
function callFeedbackMessage(inputType, inputText) {
var inputFeedback = inputType;
e.preventDefault();
if (inputType == 'Error') {
alertify.error(inputText);
return false;
}
else if (inputType == 'Success') {
alertify.success(inputText);
return false;
}
else {
alertify.log(inputText, "", 10000);
return false;
}
}
C# Code Behind of lnkSave_Click
protected void lnkSave_Click(object sender, EventArgs e)
{
Category newCategory = new ProgrammersToolkitLibrary.BOM.Category();
bool isSuccess = true;
newCategory.CategoryName = txtCategoryName.Text;
newCategory.Description = txtDescription.Text;
isSuccess = CategoryController.CreateNewCategory(newCategory);
if (isSuccess == true)
{
grdCategoriesList.DataBind();
upCategoriesList.Update();
ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "alert", "callFeedbackMessage('Success', 'Okay');", true);
}
else
{
}
}
ASP.NET Page
<%# Page Title="" Language="C#" MasterPageFile="~/Layout/Layout.Master" AutoEventWireup="true" CodeBehind="Category_List.aspx.cs" Inherits="ProgrammersToolkit.Views.Maintenance.Categories.Category_List" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"></asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<div style ="text-align:left;">
<h3>Article Categories</h3>
<div class="btn-group">
<button class="btn btn-default" data-toggle="modal" data-target="#AddCategoryModal"><span class="glyphicon glyphicon-plus"></span> Add Category</button>
<asp:LinkButton ID="LinkButton2" runat="server" CssClass="btn btn-default"><img src="../../../Layout/img/Icon_Excel.gif" /> Export to Excel</asp:LinkButton>
<asp:LinkButton ID="LinkButton3" runat="server" CssClass="btn btn-default"><img src="../../../Layout/img/Icon_Excel.gif" /> Import from Excel</asp:LinkButton>
</div>
</div>
<br /><br />
<div class="panel panel-default">
<div class="panel-heading">
<div class="row">
<div class ="col-lg-6">
<div class="input-group">
<asp:TextBox ID="txtSearch" runat="server" CssClass="form-control"></asp:TextBox>
<span class="input-group-btn">
<asp:LinkButton ID="lnkSearch" runat="server" CssClass="btn btn-default">Search</asp:LinkButton>
<asp:LinkButton ID="lnkReset" runat="server" CssClass="btn btn-default">Reset</asp:LinkButton>
</span>
</div>
</div>
<div class ="col-lg-6"></div>
</div>
</div>
<div class="panel-body">
<asp:UpdatePanel ID="upCategoriesList" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:GridView ID="grdCategoriesList" runat="server" CssClass = "table table-hover table-responsive" Width="100%"
DataSourceID="odsCategoriesList" AllowPaging="true" PageSize="10" GridLines="None" BorderStyle="NotSet" BorderWidth="0px"
AutoGenerateColumns="false">
<PagerSettings FirstPageText="<< First" LastPageText="Last >>" NextPageText="Next >"
Position="Bottom" PreviousPageText="< Previous" />
<Columns>
<asp:TemplateField HeaderStyle-CssClass="input-group-addon" ItemStyle-CssClass="input-group-addon">
<ItemTemplate>
<asp:CheckBox ID="chkSelectItem" runat="server" />
</ItemTemplate>
<HeaderTemplate>
<asp:CheckBox ID="chkSelectAll" runat="server" />
</HeaderTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText = "Category Name" ItemStyle-HorizontalAlign="Left">
<ItemTemplate>
<asp:LinkButton ID="lnkCategoryName" runat="server" OnCommand="lnkCategoryName_Command"
CommandArgument='<%# Eval("CategoryId") %>' CommandName='<%# Eval("CategoryName") %>'
Text='<%# Eval("CategoryName") %>'></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Description" HeaderText="Description" ItemStyle-HorizontalAlign="Left" />
</Columns>
<PagerStyle HorizontalAlign="Right" />
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
</div>
<asp:ObjectDataSource ID="odsCategoriesList" runat="server" EnablePaging="True" TypeName="ProgrammersToolkitLibrary.Controller.CategoryController"
SelectMethod="GetListOfCategories" SelectCountMethod="GetListOfCategoriesCount"></asp:ObjectDataSource>
</div>
<div class="modal fade" id="AddCategoryModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Add New Category</h4>
</div>
<div class="modal-body">
<table style="width:100%;text-align:left;">
<tr>
<td style = "width: 30%;"><label for="txtCategoryName">Category Name:</label></td>
<td>
<asp:TextBox ID="txtCategoryName" runat="server" CssClass="form-control"></asp:TextBox>
</td>
</tr>
<tr>
<td style = "width:30%; vertical-align:text-top;"><label for="txtDescription">Description:</label></td>
<td>
<asp:TextBox ID="txtDescription" runat="server" TextMode="MultiLine" Rows="3" CssClass="form-control"></asp:TextBox>
</td>
</tr>
</table>
</div>
<div class="modal-footer">
<asp:LinkButton ID="lnkSave" runat="server" CssClass="btn btn-primary" OnClick="lnkSave_Click" ClientIDMode="Static">Save</asp:LinkButton>
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</asp:Content>
Thank you.
Ju-chan

trying to dynamic asp:FileUpload , refresh trouble

i need the users of my web system to do uploads ( up 4 ).
the upload itself its working , but i dont want all for box appering at start, so tried to hide the 2nd ,3rd and 4th upload boxes until the user need them .
here the aspx code part
<fieldset>
<div class="frm tam">
</div>
<div class="lin">
<asp:FileUpload ID="FileUpload1" runat="server" /></div>
<div class="lin">
<asp:FileUpload ID="FileUpload2" runat="server" Visible="false" /></div>
<div class="lin">
<asp:FileUpload ID="FileUpload3" runat="server" Visible="false" /></div>
<div class="lin">
<asp:FileUpload ID="FileUpload4" runat="server" Visible="false" /></div>
<div class="lin">
<asp:Button ID="btnUpload" runat="server" Text="Upload"OnClick="btnUpload_Click" />
<asp:Button ID="btnAdd" runat="server" Text="ADD File" OnClick="btnAdd_Click" />
<asp:Button ID="btnRem" runat="server" Text="Remove File" OnClick="btnRem_Click" />
</div>
</fieldset>
and the code behind to show and hide the boxes
protected void btnAdd_Click(object sender, EventArgs e)
{
if (FileUpload2.Visible == false)
{
FileUpload2.Visible = true;
}
else if (FileUpload3.Visible == false)
{
FileUpload3.Visible = true;
}
else if (FileUpload4.Visible == false)
{
FileUpload4.Visible = true;
}
}
protected void btnRem_Click(object sender, EventArgs e)
{
if (FileUpload4.Visible == true)
{
FileUpload4.Visible = false;
}
else if (FileUpload3.Visible == true)
{
FileUpload3.Visible = false;
}
else if (FileUpload2.Visible == true)
{
FileUpload2.Visible = false;
}
}
and when i click on Add File, the new box appear but the filepaths selected on the other boxes are cleared. Can i avoid this clear ?
*edit: i´m using net framework 4.0 .
The file get lost on postback. Alternatively, you can achieve that with JavaScript
<div id="div1">
<asp:FileUpload ID="FileUpload1" runat="server" />
</div>
<div id="div2" style="display:none"> <!-- visibility:hidden -->
<asp:FileUpload ID="FileUpload2" runat="server" />
</div>
<div id="div3" style="display:none">
<asp:FileUpload ID="FileUpload3" runat="server" />
</div>
<div id="div4" style="display:none">
<asp:FileUpload ID="FileUpload4" runat="server" />
</div>
Then put each FileUpload control in each of the divs.
<input type="button" valud="Add" onclick="addControls()" />
Then use JavaScript to make them visible
function addControls()
{
document.getElementById('div2').style.display = 'inline-block';
//$('#div2').show(); <--- JQuery
}
The problem here is that uploading files works slightly differently to most input controls...
Rather than posting the file path value that is entered, it actually posts the file content so
on postback this value gets lost.
It seems to me like your best bet is to do something with javascript on the client to show/hide these upload controls. This would also be a better user experience as the user wouldn't have to wait for postback each time.
You could do this with jQuery...
http://jsfiddle.net/BAwfH/2/
<fieldset>
<div class="frm tam">
</div>
<div class="lin">
<asp:FileUpload ID="FileUpload1" runat="server" />
</div>
<div class="lin">
<asp:FileUpload ID="FileUpload2" runat="server" />
</div>
<div class="lin">
<asp:FileUpload ID="FileUpload3" runat="server" />
</div>
<div class="lin">
<asp:FileUpload ID="FileUpload4" runat="server" />
</div>
<div>
<asp:Button ID="btnUpload" runat="server" Text="Upload"OnClick="btnUpload_Click" />
<asp:Button ID="btnAdd" class="add-button" runat="server" Text="ADD File" OnClick="btnAdd_Click" />
<asp:Button ID="btnRem" runat="server" Text="Remove File" OnClick="btnRem_Click" />
</div>
<script type="text/javascript">
$(document).ready(function(){
var lines = $('.lin');
lines.hide();
lines.filter(':first').show();
$('.add-button').click(function(){
lines.filter(':hidden:first').show();
if(lines.filter(':hidden').length == 0)
$(this).hide();
});
});

asp.net button in css overlay div on masterpage not firing on click event

Im fairly new to umbraco, master pages and all that, but im catching on..
I seem to have this weird problem.. I have a set of master pages with content with umbraco cms..
In the master pages i have a common menu and a login button.. This login button fires up an overlay, wich is contained in a div within the same masterpage. There is another overlay to create a new user on that same master page.. Problem is, the button OnClick in the login overlay does not fire.. Funny thing is, the required property on my textboxes does fire... You know, the message popping up saying you must enter something! But my custom validator does nothing :S
Here is the script in the header of my masterpage:
<script runat="server">
private void btnLogin_Click(object sender, EventArgs e)
{
Session["failedLogin"] = false;
string mail = tbLoginMail.Text.Trim();
string pass = tbLoginPass.Text;
tbLoginMail.Text = "TEEEEEEST!";
PageUtil.User = PageUtil.ValidateCredentials(mail, pass);
if (PageUtil.User == null)
{
Session["failedLogin"] = true;
}
if (Page.IsValid)
Server.Transfer(Page.ResolveClientUrl("/"));
}
private void UserLoginResponse(object source, ServerValidateEventArgs args)
{
if (Session["failedLogin"] != null)
{
if ((bool)Session["failedLogin"])
{
args.IsValid = false;
}
}
}
</script>
Not even the text in the textbox gets set to teeeesst! Any1 has any suggestions?
Here is the body containing the 2 divs:
<body>
<a name="LoginLink" href="#overlay" class="submitbtn"><%= PageUtil.IsLoggedIn() ? "Log ud" : "Log Ind" %></a>
<form runat="server">
<div id="overlay">
<div id="popup">
<!-- ANY CONTENTS -->
<a href="">
<img class="close_button" src="/media/Images/close.png" /></a>
<div id="login" class="login">
<asp:CustomValidator ID="CustomValidator1" runat="server" ValidationGroup="login" ErrorMessage="Forkert e-mail eller password" OnServerValidate="UserLoginResponse" Display="Dynamic"></asp:CustomValidator><br />
<label>E-mail</label>
<asp:TextBox ID="tbLoginMail" type="text" TabIndex="1" class="input" ValidationGroup="login" placeholder="email eller brugernavn" required="true" runat="server" /><br>
<br>
<label>Password</label>
<asp:TextBox ID="tbLoginPass" type="password" class="input" TabIndex="2" required="true" ValidationGroup="login" runat="server" /><br>
<br>
<asp:CheckBox ID="cbRememberMe" type="checkbox" TabIndex="3" runat="server" />Keep me logged in
<asp:Button ID="submitbtn" Text="Login" TabIndex="4" OnClick="btnLogin_Click" runat="server" ValidationGroup="login" CausesValidation="true" /><br />
Ikke oprettet? Opret bruger!
</div>
</div>
</div>
<div id="overlay_signup">
<div class="overlay popup" style="height: 500px;">
<a href="#">
<img class="close_button" src="/media/Images/close.png" /></a>
<div class="login">
<label>Navn</label>
<asp:TextBox ID="createUserName" type="text" TabIndex="1" ValidationGroup="signUp" class="input" placeholder="Navn" required="true" runat="server" /><br>
<br>
<label>Email</label>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
<asp:TextBox ID="createUserMail" type="text" class="input" ValidationGroup="signUp" placeholder="e-mail" TabIndex="2" required="true" runat="server" /><br>
<br>
<label>Password</label>
<asp:TextBox ID="tbCreateUserPass" type="password" ValidationGroup="signUp" class="input" TabIndex="2" required="true" runat="server" /><br>
<br>
<asp:Button runat="server" ID="submit1" class="submitbtn" ValidationGroup="signUp" Text="SignUp" TabIndex="4" />
</div>
</div>
</div>
<div id="box">
<div id="head">
<umbraco:Macro ID="Macro1" Alias="MenuBar" runat="server"></umbraco:Macro>
</div>
<div class="header">
<umbraco:Item ID="Item2" Field="header" runat="server" />
</div>
<div id="content">
<umbraco:Item ID="Item1" Field="bodyText" runat="server" />
<div id="contentDiv">
<asp:ContentPlaceHolder ID="pageContent" runat="server" />
</div>
</div>
<div class="dotSeperator">...</div>
<div id="footer">
<p class="footerText">| Martin Stendorf Jensen | Copyright ® 2013 | mstendorf#outlook.com | +4527126901 |</p>
</div>
</div>
</form>

Categories