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
Related
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 have a search webpage where the user can apply for jobs. The jobs are displayed through repeater control. When the user clicks on apply button I want a modal to popup with two textboxes containing the companies email and the job name. Now when I am not passing passing at that time the modal pops up but when I try to pass values from repeater than the modal doesn't show up. I have searched a lot and even tried something. With what I have tried I am not getting an error but the modal is not showing up. Here is my code
.aspx code for repeater
<asp:Repeater ID="RepterDetails" runat="server" OnItemCommand="RepterDetails_ItemCommand">
<HeaderTemplate>
<table style="border:1px solid; width:800px" cellpadding="2" cellspaing="2">
<tr style=" color:#000000; font-size: large; font-weight: bold;">
<td colspan="2">
<b>JOBS Available</b>
</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<table style="border-top:3px solid; width:800px" >
<tr>
<td style="color:black" >
COMPANY:
<asp:Label ID="lblcmp" runat="server" Text='<%#Eval("cmp_name")%>' Font-Bold="true" ForeColor="black"/>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td style="color:black">
LOCATION:
<asp:Label ID="lbl_city" runat="server" Text='<%#Eval("city_name") %>' ForeColor="black"/>,
<asp:Label ID="lbl_state" runat="server" Text='<%#Eval("state_name") %>' ForeColor="black"/>
</td>
</tr>
<tr>
<td style="color:black">
Job:
<asp:Label ID="lbl_jname" runat="server" Font-Bold="true" Text='<%#Eval("job_name") %>' ForeColor="black"/>
</td>
</tr>
<tr>
<td style="color:black">
Job Details:
<asp:Label ID="lbl_jdet" runat="server" Text='<%#Eval("job_details") %>' ForeColor="black"/>
</td>
</tr>
<tr>
<td style="color:black">
Experience :
<asp:Label ID="lbl_jexp" runat="server" Text='<%#Eval("experience") %>' ForeColor="black"/>
</td>
</tr>
<tr>
<td style="color:black">
Job-Type :
<asp:Label ID="lbl_jobtype" runat="server" Text='<%#Eval("job_type") %>' ForeColor="black"/>
</td>
</tr>
<tr>
<td>
<table>
<tr>
<td style="color:black" >Comapny Email: <asp:LinkButton ID="link_cemail" runat="server" CommandName='<%#Eval("cemail") %>' CommandArgument='<%#Eval("cemail") %>' Text='<%#Eval("cemail") %>' ForeColor="black" OnClick="link_cemail_Click" ></asp:LinkButton></td>
</tr>
</table>
<tr>
<td>
<asp:Button runat="server" ID="btn_apply" CommandName="popup" OnClick="btn_apply_Click" Text="apply"/>
<script type="text/javascript">
function openModal() {
$('#exampleModal').modal('show');
}
</script>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" RenderMode="Inline">
<ContentTemplate>
<asp:Button runat="server" ID="btn_save" OnClick="btn_save_Click" AutoPostBack="true" Text="Save" Height="34px"/>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btn_save" />
</Triggers>
</asp:UpdatePanel>
</td>
</tr>
</td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
Modal code
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered"> <div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Apply for Job</h5> <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
Company Email : <asp:TextBox ID="txt_email" runat="server" ReadOnly="true" ></asp:TextBox><br /><br />
Job-Name : <asp:TextBox ID="txt_app_jname" runat="server" ReadOnly="true"></asp:TextBox>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button></div>
</div>
This is my code behind
protected void btn_apply_Click(object sender, EventArgs e)
{
RepeaterItem item = (sender as Button).Parent as RepeaterItem;
string cemail = (item.FindControl("link_cemail") as System.Web.UI.WebControls.LinkButton).Text;
txt_email.Text = cemail;
ClientScript.RegisterStartupScript(GetType(), "popup", "openModal()", true);
}
I have tried this and I am not getting any error but my modal is not opening up.
please can someone help me?
This is my advice:
I use for asp.net projects Ajaxtoolkit: http://www.ajaxtoolkit.net/
Then I add in my project the dll
In my aspx page, I added this line to work with ajax controls
For modal scream I did the next:
Used ajx:ModalPopupExtender
Put the modal in asp panel
Resume of my code:
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajx" %>
<ajx:ModalPopupExtender ID="mppPagos" runat="server" PopupControlID="pnl_PagosModal" TargetControlID="lk_BusquedaPagos" BackgroundCssClass="modalBackground">
</ajx:ModalPopupExtender>
<asp:HiddenField ID="lbl_IdAbono" Value="0" runat="server"/>
<div class="form-group row">
<div class="control-label col-lg-offset-0 col-md-2 col-lg-2">
<asp:LinkButton runat="server" CssClass="btn btn-success btn-sm" ID="lk_BusquedaPagos" Text=">> Agregar Pagos <<"></asp:LinkButton>
</div>
<div>
<asp:Button ID="btn_EliminarPagosRenta" CssClass="btn btn-success btn-sm" runat="server" Text="Eliminar Pago" OnClick="btn_EliminarPagosRenta_Click" />
</div>
</div>
<asp:Panel ID="pnl_PagosModal" runat="server" CssClass="panel EstiloPanel" ScrollBars="Vertical">
<asp:UpdatePanel ID="upl_ModalPagos" runat="server">
<ContentTemplate>
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<div class="close">
<asp:Button ID="btnCerrarModalPago" runat="server" Text="x" CssClass="btn-xs" OnClick="btnCerrarModalPago_Click"/>
</div>
<h5 class="modal-title">Pagos</h5>
<asp:Label ID="lbl_ErrorPagos" runat="server" Text="" ForeColor="Red"></asp:Label>
</div>
<div class="modal-body">
<div class="tab-pane fade in active" id="tab3_1">
<asp:HiddenField ID="HiddenField2" runat="server"/>
<div class="form-group row">
<asp:Label ID="lbl_FormaPago" CssClass="control-label col-lg-offset-0 col-md-2 col-lg-2" runat="server" Text="Forma de Pago:"></asp:Label>
<div class="col-md-4 col-lg-3">
<telerik:RadComboBox ID="rad_ddl_FormaPago" runat="server" Height="100%" Width="100%" OnSelectedIndexChanged="rad_ddl_FormaPago_SelectedIndexChanged"
ZIndex="10000000" AutoPostBack="true"
EmptyMessage="Seleccionar Forma Pago" MarkFirstMatch="true" EnableLoadOnDemand="true">
</telerik:RadComboBox>
</div>
<asp:Label ID="lbl_NumeroTarjeta" CssClass="control-label col-lg-offset-0 col-md-2 col-lg-2" runat="server" Text="Número de Tarjeta:"></asp:Label>
<div class="col-md-4 col-lg-3">
<asp:TextBox ID="txtNumeroTarjeta" CssClass="form-control" runat="server"></asp:TextBox>
</div>
</div>
<div class="form-group row">
<asp:Label ID="lbl_MontoPago" CssClass="control-label col-lg-offset-0 col-md-2 col-lg-2" runat="server" Text="Monto Pago:"></asp:Label>
<div class="col-md-4 col-lg-3">
<asp:TextBox ID="txtMontoPago" CssClass="form-control" runat="server"></asp:TextBox>
</div>
<asp:Label ID="lbl_Cambio" CssClass="control-label col-lg-offset-0 col-md-2 col-lg-2" runat="server" Text="Cambio:"></asp:Label>
<div class="col-md-4 col-lg-3">
<asp:TextBox ID="txtMontoCambio" CssClass="form-control" runat="server"></asp:TextBox>
</div>
</div>
<div class="form-group row">
<asp:Label ID="lbl_DescGarantia" CssClass="control-label col-lg-offset-0 col-md-2 col-lg-2" runat="server" Text="Descripción de garantía:" Visible="false"></asp:Label>
<div class="col-md-4 col-lg-3">
<asp:TextBox ID="txt_DescGarantia" CssClass="form-control" runat="server" Visible="false"></asp:TextBox>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<asp:Button ID="btnAgregarPago" runat="server" Text="Agregar Pago" CssClass="btn btn-success btn-sm" OnClick="btnAgregarPago_Click" />
<asp:Button ID="btnAgregarMontoTarjeta" runat="server" Text="Agregar Monto Tarjeta" CssClass="btn btn-success btn-sm" OnClick="btnAgregarMontoTarjeta_Click" />
</div>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
I'm developing a blog that has a section for getting some comments and replies from the users. The first part is of my code for getting the comments and replies is the following one:
C# code:
var a = commentBLL.GetAll(BlogID);
rp_MainComments.DataSource = a;
rp_MainComments.DataBind();
protected void rp_MainComments_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem)
{
LinkButton btn = e.Item.FindControl("btn_Comment_Reply") as LinkButton;
ScriptManager.GetCurrent(this).RegisterAsyncPostBackControl(btn);
HiddenField lt = (HiddenField)e.Item.FindControl("hf_Main_CommentID");
Repeater rpcommentreply = (Repeater)e.Item.FindControl("rp_Comment_Reply");
Panel panel_Comment_Reply = e.Item.FindControl("panel_Comment_Reply") as Panel;
if (!string.IsNullOrEmpty(lt.Value))
{
var b = commentBLL.GetByCommentID(Convert.ToInt32(lt.Value));
rpcommentreply.DataSource = b;
rpcommentreply.DataBind();
panel_Comment_Reply.Visible = false;
}
}
}
ASPX code:
<asp:Repeater ID="rp_MainComments" OnItemDataBound="rp_MainComments_ItemDataBound" OnItemCommand="rp_MainComments_ItemCommand" runat="server">
<ItemTemplate>
<asp:HiddenField ID="hf_Main_CommentID" runat="server" Value='<%# Eval("Comment_Id") %>' />
<ul class="comments">
<li>
<div class="comment">
<div class="img-thumbnail d-none d-sm-block">
<%--<asp:Image ID="Image_7" CssClass="avatar" runat="server" ImageUrl="http://placehold.it/40x40" />--%>
<i class="fa fa-user fa-fw fa-5x"></i>
</div>
<div class="comment-block">
<div class="comment-arrow"></div>
<span class="comment-by">
<strong><%# Eval("Name") %></strong>
<span class="float-right">
<span>
<asp:LinkButton ID="btn_Comment_Reply" Text="Reply" ClientIDMode="AutoID" runat="server" OnClick="btn_Comment_Reply_Click" CommandName="Edit" CommandArgument='<%# Eval("Comment_Id") %>' /></span>
</span>
</span>
<p><%# Eval("Message") %></p>
<span class="date float-right">
<%# Eval("Comment_Date") %></span>
</div>
</div>
</li>
<li>
<asp:HiddenField ID="hf_PanelValue" Value='<%# Container.ItemIndex %>' runat="server" />
<asp:Repeater ID="rp_Comment_Reply" OnItemCommand="rp_Comment_Reply_ItemCommand" runat="server">
<ItemTemplate>
<ul class="comments reply" id="commentreply">
<li>
<div class="comment">
<div class="img-thumbnail d-none d-sm-block">
<%--<asp:Image ID="Image_8" CssClass="avatar" runat="server" ImageUrl="http://placehold.it/40x40" />--%>
<i class="fa fa-user fa-5x fa-fw"></i>
</div>
<div class="comment-block">
<div class="comment-arrow"></div>
<span class="comment-by">
<strong><%# Eval("Name") %></strong>
<span class="float-right">
<span>
<asp:LinkButton ID="btn_Reply" Text="Reply" ClientIDMode="AutoID" runat="server" OnClick="btn_Reply_Click" CommandName="Edit" CommandArgument='<%# Eval("Parent_Id") %>' /></span></span>
</span>
<p><%# Eval("Message") %></p>
<span class="date float-right"><%# Eval("Comment_Date") %></span>
</div>
</div>
</li>
</ul>
</ItemTemplate>
</asp:Repeater>
</li>
</ul>
</ItemTemplate>
</asp:Repeater>
This is the output:
Now, I would like to to show the nested replies to which user reply in a post it's shown only upto second level but I need a third as well as fourth level.
How is it possible?
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"/> 
<input type="button" id="btnDelete" class="btn btn-danger" value="Delete"/> 
<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.
There is four Div tags in this GridView with ID="NUMBER1" ID="NUMBER2" ID="NUMBER3" ID="NUMBER4" values and i want to change the sequence of their position in page randomly in every row of the gridview.
what is the best and most simple SERVER SIDE method to do this.
I'm new to asp.net using C# language.
<body>
<asp:GridView OnRowCommand="SelectedPollGridView_RowCommand" ID="SelectedPollGridView" runat="server" AutoGenerateColumns="False" DataKeyNames="QuesID" DataSourceID="SelectedPollSqlDataSource">
<Columns>
<asp:TemplateField HeaderText="Questions">
<ItemTemplate>
<div runat="server" id="MainDiv" class="text-right col-md-12">
<div class="row ">
<div dir="rtl" class="col-md-12 text-right">
<p runat="server" id="BodyPTag"><%#Eval("Body") %></p>
<asp:Label Visible="false" ID="QuesIDLabel" runat="server" Text='<%#Eval("QuesID") %>'></asp:Label>
</div>
</div>
<div id="NUMBER1" runat="server" class="row ">
<div class="col-md-12">
<div dir="rtl" runat="server" id="Div2" class="text-right col-md-11">
<asp:Label ID="Label1" runat="server" Text='<%#Eval("O1") %>'></asp:Label>
</div>
<div runat="server" id="Div3" class="text-right col-md-1">
<asp:Button CommandArgument='<%# ((GridViewRow) Container).RowIndex %>' CommandName="O1" CssClass='<%#Eval("O1Css") %>' ID="O1Button" runat="server" Text="Option 1" />
</div>
</div>
</div>
<div id="NUMBER2" runat="server" class="row ">
<div class="col-md-12">
<div dir="rtl" runat="server" id="Div4" class="text-right col-md-11">
<asp:Label ID="Label2" runat="server" Text='<%#Eval("O2") %>'></asp:Label>
</div>
<div runat="server" id="Div5" class="text-right col-md-1">
<asp:Button CommandArgument='<%# ((GridViewRow) Container).RowIndex %>' CommandName="O2" CssClass='<%#Eval("O2Css") %>' ID="O2Button" runat="server" Text="Option 2" />
</div>
</div>
</div>
<div id="NUMBER3" runat="server" class="row ">
<div class="col-md-12">
<div dir="rtl" runat="server" id="Div6" class="text-right col-md-11">
<asp:Label ID="Label3" runat="server" Text='<%#Eval("O3") %>'></asp:Label>
</div>
<div runat="server" id="Div7" class="text-right col-md-1">
<asp:Button CommandArgument='<%# ((GridViewRow) Container).RowIndex %>' CommandName="O3" CssClass='<%#Eval("O3Css") %>' ID="O3Button" runat="server" Text="Option 3" />
</div>
</div>
</div>
<div id="NUMBER4" runat="server" class="row ">
<div class="col-md-12">
<div dir="rtl" runat="server" id="Div8" class="text-right col-md-11">
<asp:Label ID="Label4" runat="server" Text='<%#Eval("O4") %>'></asp:Label>
</div>
<div runat="server" id="Div9" class="text-right col-md-1">
<asp:Button CommandArgument='<%# ((GridViewRow) Container).RowIndex %>' CommandName="O4" CssClass='<%#Eval("O4Css") %>' ID="O4Button" runat="server" Text="Option 4" />
</div>
</div>
</div>
</div>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SelectedPollSqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:GUOTSConnectionString %>" SelectCommand="SELECT DISTINCT QuesID, Body, O1, O2, O4, O3, O1Css, O2Css, O4Css, O3Css, Time, BookRange, UserID, CourseID, Code FROM Question WHERE (UserID = #userid) AND (Code = #code)">
<SelectParameters>
<asp:QueryStringParameter Name="code" QueryStringField="code" />
<asp:SessionParameter Name="userid" SessionField="userid" />
</SelectParameters>
</asp:SqlDataSource>
</body>
the following will do what you want.
Working FIDDLE here
first, change your current divs to give each row a class name we can pick out in our script, like "randomDiv". We could have used "row" but i was afraid you were using that in more places than just these divs.
<div id="NUMBER1" runat="server" class="row randomDiv">
then on document ready run the following javascript:
<script>
$(document).ready(function() {
var divs= $(".randomDiv");
for(var i = 0; i < divs.length; i++){
var target = Math.floor(Math.random() * divs.length -1) + 1;
var target2 = Math.floor(Math.random() * divs.length -1) +1;
divs.eq(target).before(divs.eq(target2));
}
});
</script>