I have a search button in my page. When I click the button, a paged datalist will show up
with result. I want to use modalPopupExtender with Datalist and collection pager. Is it possible ? Here is the code i tried but it doesn't work :
<asp:Label ID="Label5" runat="server"></asp:Label>
<asp:ModalPopupExtender ID="Label1_ModalPopupExtender" runat="server" CancelControlID="btThoat"
DynamicServicePath="" Enabled="True" PopupControlID="Panel1" TargetControlID="Label5">
</asp:ModalPopupExtender>
<asp:Panel ID="Panel1" runat="server">
<div style="margin-left: 20px; padding-top: 50px">
<asp:Label ID="lbl_CS" runat="server" Text="Ca sĩ" ForeColor="#FF33CC" Font-Size="18"
Visible="True"></asp:Label>
<asp:DataList ID="DataList1" runat="server" BackColor="White" BorderColor="#CC9966"
BorderStyle="None" BorderWidth="1px" CellPadding="4" GridLines="Both" RepeatColumns="4"
OnItemDataBound="DataList1_ItemDataBound">
<FooterStyle BackColor="#FFFFCC" ForeColor="#330099" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="#FFFFCC" />
<ItemStyle BackColor="White" ForeColor="#330099" />
<ItemTemplate>
<table>
<tr>
<td style="width: 10px">
<asp:RadioButton ID="rd_CS" runat="server" GroupName="Casi" Text='<%# Eval("MaCS")%>'
AutoPostBack="False"></asp:RadioButton>
</td>
<td style="width: 75px">
<asp:Image ID="Img_Casi" runat="server" ImageUrl='<%#Eval("Hinhanh")%>' Width="75px"
Height="75px" BorderColor="#66FF33" />
</td>
<td style="width: 50px">
<asp:Label ID="lbl_Ten" runat="server" Text='<%#Eval("TenCS")%>'></asp:Label>
</td>
<td style="width: 40px">
<asp:Label ID="lbl_Ngaysinh" runat="server" Text='<%#Eval("Ngaysinh")%>'></asp:Label>
</td>
</tr>
</table>
</ItemTemplate>
<SelectedItemStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="#663399" />
</asp:DataList>
<cc2:CollectionPager ID="CollectionPager1" runat="server" MaxPages="1000" PagingMode="QueryString"
BackNextDisplay="Buttons" QueryStringKey="Datalist1">
</cc2:CollectionPager>
</div>
</asp:Panel>
Code in c#:
bool Checkcs()
{
string cs = "select MaCS, Quocgia, TenCS, Hinhanh, Thongtin, cast(convert(char(11), Ngaysinh, 113) as char) as Ngaysinh from casi where tencs like N'%" + txt_CS.Text + "%'";
da = new SqlDataAdapter(cs, cnn);
dtSP = new DataTable();
cnn.Open();
da.Fill(dtSP);
cnn.Close();
CollectionPager1.PageSize = 8;
CollectionPager1.DataSource = dtSP.DefaultView;
CollectionPager1.BindToControl = DataList1;
DataList1.DataSource = CollectionPager1.DataSourcePaged;
DataList1.DataBind();
Label1_ModalPopupExtender.Show();
if (dtSP.Rows.Count != 0)
return true;
else
return false;
}
protected void img_CheckCS_Click(object sender, ImageClickEventArgs e)
{
Checkcs();
}
If it's impossible. Is there another way to do it ? If it's possible. Can you show me an example code ? Any help would be great.
This is Sample. Please refer with this
.modalBackground {
background-color: Gray;
filter: alpha(opacity=80);
opacity: 0.8;
z-index: 10000;
}
.modalPopupCss {
background-color: white;
border-width: 1px;
border-style: solid;
border-color: #0066B3;
padding: 3px;
}
ASPX
<div>
<asp:ModalPopupExtender BackgroundCssClass="modalBackground" ID="Label1_ModalPopupExtender" CancelControlID="Button2" runat="server" Enabled="True" PopupControlID="Panel1" TargetControlID="lbl_CS"></asp:ModalPopupExtender>
<asp:Panel ID="Panel1" CssClass="modalPopupCss" runat="server">
<div style="margin-left: 20px; padding-top: 50px">
<asp:Label ID="lbl_CS" runat="server" Text="" ForeColor="#FF33CC" Font-Size="18" Visible="True"></asp:Label>
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<asp:GridView ID="GridView1" runat="server"></asp:GridView>
<asp:Button ID="Button2" runat="server" Text="Close" />
</div>
</asp:Panel>
<asp:Button ID="Button1" runat="server" Text="Search" OnClick="Button1_Click" />
Aspx.Cs
DataTable dt = new DataTable();
protected void Page_Load(object sender, EventArgs e)
{
dt.Columns.Add("ID");
dt.Columns.Add("Name");
dt.Columns.Add("State");
}
protected void Button1_Click(object sender, EventArgs e)
{
dt.Rows.Add("1", "Vignesh", "True");
GridView1.DataSource = dt;
GridView1.DataBind();
Label1_ModalPopupExtender.Show();
}
Related
I have a gridview with dynamic controls. Resource name is something that I am picking up from Active directory. Search filter works in a way where you have to enter lastname, firstname and onlclick of lookup it will search. If there are more than one record a modalpopup will be displayed with dropdownlist with options to select from.
The issue is that I am unable to get the dropdown values populated into textbox present in gridview. I need this dropdown value in correct selected row's textbox.
Code behind:
protected void gvProjectResource_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Lookup")
{
GridViewRow clickedRow = ((LinkButton)e.CommandSource).NamingContainer as GridViewRow;
TextBox t2 = ((TextBox)clickedRow.FindControl("t2"));
DataTable dt = globalObj.FindPersons(t2.Text.Split(',')[0].Trim(), t2.Text.Split(',')[1].Trim());
if (dt.Rows.Count > 1)
{
mpFindPerson.Show();
ddlPersons.Items.Clear();
ddlPersons.Items.Add(new ListItem { Value = "0", Text = "-Select User-" });
ddlPersons.DataSource = dt;
dt.Columns.Add("FullName", typeof(string), "DisplayName + ' | ' + MSID");
ddlPersons.DataTextField = "FullName";
ddlPersons.DataValueField = "MSID";
ddlPersons.DataBind();
}
else
{
t2.Text = dt.Rows[0].ItemArray[0].ToString();
}
}
if (e.CommandName == "Del")
{
}
}
protected void btnSelectPerson_Click(object sender, EventArgs e)
{
TextBox t2 = (gvProjectResource.SelectedRow.FindControl("t2") as TextBox);
t2.Text = ddlPersons.SelectedItem.Text;
mpFindPerson.Hide();
}
ASPX Code:
<div id="four">
<fieldset style="border: solid; border-width: thin; height: 220px; border-color: #a8a8a8;">
<legend id="Legend11" runat="server" visible="true" style="width: auto; margin-bottom: 0px; font-size: 12px; font-weight: bold; color: #1f497d;"> Project Resources </legend>
<div style="height: 210px; overflow: auto;">
<asp:GridView ID="gvProjectResource" Width="88%" HeaderStyle-Font-Size="X-Small" CssClass="labels" runat="server"
ShowFooter="true" AutoGenerateColumns="false" Style="margin-right: auto; margin-left:7px;"
OnRowDataBound="gvProjectResource_RowDataBound"
OnRowCommand="gvProjectResource_RowCommand" >
<Columns>
<asp:TemplateField HeaderText="Role" ItemStyle-VerticalAlign="Top" FooterStyle-VerticalAlign="Top" ItemStyle-Width="50%">
<ItemTemplate>
<asp:Label ID="lblRole" runat="server" Text='<%# Eval("role") %>' Visible="false" />
<asp:DropDownList ID="ddlRole" Height="23px" Width="98%" runat="server" CssClass="DropDownListStyleOverview"></asp:DropDownList>
</ItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="ddlRole2" Height="23px" Width="98%" runat="server" CssClass="DropDownListStyleOverview"></asp:DropDownList>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Resource Name" ItemStyle-VerticalAlign="Top" FooterStyle-VerticalAlign="Top" ItemStyle-Width="50%">
<ItemTemplate>
<asp:TextBox ID="t1" Height="23px" Width="98%" runat="server" ></asp:TextBox>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="t2" Height="23px" Width="68%" runat="server"></asp:TextBox>
<asp:LinkButton runat="server" Text="Lookup" CommandName="Lookup" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-VerticalAlign="Top" ItemStyle-Width="5%">
<ItemTemplate>
<asp:LinkButton runat="server" Text="Delete" CommandName="Del" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<br />
<div style="text-align: right;">
<asp:LinkButton runat="server" Text="Add New" ID="LinkButton2" CssClass="labels"></asp:LinkButton>
</div>
</div>
<asp:Button runat="server" ID="btnModalPopUpSearch" Style="display: none" />
<AjaxToolkit:ModalPopupExtender ID="mpFindPerson"
BehaviorID="mpFindPersonBehav"
runat="server"
DropShadow="true"
BackgroundCssClass="modalBackground"
PopupControlID="pnlFindPerson"
TargetControlID="btnModalPopUpSearch">
</AjaxToolkit:ModalPopupExtender>
<asp:Panel runat="Server" ID="pnlFindPerson" CssClass="modalPopup" style="position:relative;">
<div class="labels" runat="server" style="text-align:center; position:absolute; top:20%; height:10em; margin-top:auto; margin-left:20px;">
<asp:DropDownList ID="ddlPersons" runat="server" AppendDataBoundItems="true" Width="200px">
<asp:ListItem Text="-Select User-" Value="0" />
</asp:DropDownList>
<br />
<br />
<br />
<div style="text-align: center;">
<asp:Button runat="server" Font-Size="9pt" Text="Select" CssClass="buttons___" Style="float: left;"
ID="btnSelectPerson" OnClick="btnSelectPerson_Click" />
</div>
</div>
</asp:Panel>
</fieldset>
</div>
ok, so, there was nothing much to do.
have to add this.
protected void btnSelectPerson_Click(object sender, EventArgs e)
{
TextBox t2 = (TextBox)gvProjectResource.FooterRow.FindControl("t2");
t2.Text = ddlPersons.SelectedItem.Text;
mpFindPerson.Hide();
}
I have a nested gridview, And there is a textbox that named TextBoxDescription to insert user information in the second gridview. But when I want to catch textbox's (TextBoxDescription) value its return Null.
Html Code:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Width="100%"
DataKeyNames="ReportId" OnRowDataBound="GridView2_OnRowDataBound" ForeColor="#333333">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:TemplateField>
<ItemStyle Width="35px" HorizontalAlign="Center" />
<ItemTemplate>
<img alt="" style="cursor: pointer" src="plus.png" />
<asp:Panel ID="Panel5" runat="server" Style="display: none; text-align: center;">
<asp:GridView ID="GridView2" border="0" runat="server" DataKeyNames ="ReportId" OnRowCommand="GridView1_RowCommand"
Style="direction: rtl" Width="100%" Height="100%">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<table width="100%" height="100%" bgcolor="#F4F4F4">
<tr>
</tr>
<tr>
<td style="width: 50%; height: 50%" hidefocus="hidefocus" unselectable="off" valign="top">
<asp:Panel ID="Panel3" runat="server" GroupingText="یاد داشت">
<asp:TextBox ID="TextBoxDescription" runat="server" Style="resize: none; width: 612px;
height: 160px;" Text='<%# Eval("UserDescription") %>' TextMode="MultiLine"></asp:TextBox>
<br />
<br />
<asp:LinkButton ID="LinkButtonSave" CommandName ="updateData" CommandArgument='<%#Eval("ReportId") %>' runat="server">ذخیره</asp:LinkButton>
</asp:Panel>
</td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
.
.
.
C# Code:
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "updateData")
{
int i = Convert.ToInt32(e.CommandArgument);
GridViewRow row = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
TextBox tb = (TextBox)row.FindControl("TextBoxDescription");
string Text = tb.Text;
}
}
Do like below :
GridViewRow row = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
int index = row.RowIndex;
TextBox tb= (TextBox )GridView1.Rows[index].FindControl("TextBoxDescription");
http://forums.asp.net/p/2053658/5919172.aspx?Getting+textbox+s+value+in+Nested+gridview
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:TemplateField HeaderText="ID">
<ItemTemplate>
<asp:Label ID="lblid" runat="server" Text='<%#Eval("ID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Details">
<ItemTemplate>
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="false" OnRowCommand="GridView2_RowCommand">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<table>
<tr>
<td>
<asp:Panel ID="Panel3" runat="server" GroupingText="یاد داشت">
<asp:TextBox ID="TextBoxDescription" runat="server" Style="resize: none; width: 612px; height: 160px;"
Text='<%# Eval("UserDescription") %>' TextMode="MultiLine"></asp:TextBox>
<br />
<br />
<asp:LinkButton ID="LinkButtonSave" CommandName="updateData" CommandArgument='<%#Eval("ReportId") %>' runat="server">ذخیره</asp:LinkButton>
</asp:Panel>
</td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ItemTemplate>
</asp:TemplateField>
</Columns>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataTable gdv1source = new DataTable();
gdv1source.Columns.Add("ID");
gdv1source.Rows.Add("1");
GridView1.DataSource = gdv1source;
GridView1.DataBind();
}
}
protected void GridView2_RowCommand(object sender, GridViewCommandEventArgs e)
{
GridViewRow row = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
TextBox tb = (TextBox)row.FindControl("TextBoxDescription");
string Text = tb.Text;
lbltext.Text = "Text Value is: " + Text;
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
GridView gdv2 = (GridView)e.Row.FindControl("GridView2");
BindGridView2(gdv2);
}
}
private static void BindGridView2(GridView gdv2)
{
DataTable gdv2source = new DataTable();
gdv2source.Columns.Add("UserDescription");
gdv2source.Columns.Add("ReportId");
gdv2source.Rows.Add("UserDescription1", "1");
gdv2source.Rows.Add("UserDescription2", "2");
gdv2.DataSource = gdv2source;
gdv2.DataBind();
}
Hi I have an asp updatePanel which contains several asp panels. The way it should function is you click the button in the first panel it hides that panel and shows the next. That works fine the problem comes with the next panel. If I try and use either of the button controls within that panel nothing happens.
Heres the html
<asp:UpdatePanel runat="server" ChildrenAsTriggers="true">
<ContentTemplate>
<asp:Panel ID="pnlAppRej" runat="server" HorizontalAlign="Center" CssClass="textBox"
Width="85%" Visible="True">
<div style="text-align:left; width:90%">
<asp:Label ID="lblAppRej" runat="server" Text="Label"></asp:Label>
</div>
<asp:Button ID="btnApprove" runat="server" Text="Approve" CssClass="button" Style="margin-right: 20px;
margin-top: 10px" Width="100px" onclick="btnApprove_Click" />
<asp:Button ID="btnReject" runat="server" CssClass="button" Text="Reject" Style="margin-left: 20px"
Width="100px" onclick="btnReject_Click" />
</asp:Panel>
<asp:Panel runat="server" ID="pnlRejCom" Width="85%" Visible="False" CssClass="textBox">
<div style="text-align: left">
Comments<br />
</div>
<asp:TextBox ID="tbRejCom" runat="server" Height="54px" TextMode="MultiLine" Width="95%"
CssClass="textBox" Style="margin-top: 5px" ValidationGroup="rejCom"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="tbRejCom"
ErrorMessage="RequiredFieldValidator" ValidationGroup="rejCom">*</asp:RequiredFieldValidator>
<br />
<div style="text-align: center">
<asp:Button ID="btnBackRejCom" runat="server" CssClass="button" Text="Back" Style="margin-right: 20px;
margin-top: 10px" Width="100px" />
<asp:Button ID="btnDoneRejCom" runat="server" CssClass="button" Text="Done" Style="margin-left: 20px;
margin-top: 10px" Width="100px" ValidationGroup="rejCom"
onclick="btnDoneRejCom_Click" />
</div>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
c# code
protected void btnReject_Click(object sender, EventArgs e)
{
pnlRejCom.Visible = true;
pnlAppRej.Visible = false;
}
protected void btnBackRejCom_Click(object sender, EventArgs e)
{
pnlRejCom.Visible = false;
pnlAppRej.Visible = true;
}
its the btnBackRejCom_Click method which doesnt seem to fire. But I have tested setting the pnlRejCom to visible and the method works fine.
Thanks in advance
Charlie
your problem seems to be different.
I would suggest, delete the
protected void btnBackRejCom_Click(object sender, EventArgs e){}
and again create a new event.
This is what i tried and is working fine now.
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<Triggers>
<asp:PostBackTrigger ControlID="btnReject" />
<asp:AsyncPostBackTrigger ControlID="btnBackRejCom" />
<asp:PostBackTrigger ControlID="btnDoneRejCom" />
</Triggers>
<ContentTemplate>
<asp:Panel ID="pnlAppRej" runat="server" HorizontalAlign="Center" CssClass="textBox"
Width="85%" Visible="True">
<div style="text-align: left; width: 90%">
<asp:Label ID="lblAppRej" runat="server" Text="Label"></asp:Label>
</div>
<asp:Button ID="btnApprove" runat="server" Text="Approve" CssClass="button" Style="margin-right: 20px; margin-top: 10px"
Width="100px" OnClick="btnApprove_Click" />
<asp:Button ID="btnReject" runat="server" CssClass="button" Text="Reject" Style="margin-left: 20px"
Width="100px" OnClick="btnReject_Click" />
</asp:Panel>
<asp:Panel runat="server" ID="pnlRejCom" Width="85%" Visible="False" CssClass="textBox">
<div style="text-align: left">
Comments<br />
</div>
<asp:TextBox ID="tbRejCom" runat="server" Height="54px" TextMode="MultiLine" Width="95%"
CssClass="textBox" Style="margin-top: 5px" ValidationGroup="rejCom"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="tbRejCom"
ErrorMessage="RequiredFieldValidator" ValidationGroup="rejCom">*</asp:RequiredFieldValidator>
<br />
<div style="text-align: center">
<asp:Button ID="btnBackRejCom" runat="server" CssClass="button" Text="Back" Style="margin-right: 20px; margin-top: 10px"
Width="100px" OnClick="btnBackRejCom_Click1" />
<asp:Button ID="btnDoneRejCom" runat="server" CssClass="button" Text="Done" Style="margin-left: 20px; margin-top: 10px"
Width="100px" ValidationGroup="rejCom"
OnClick="btnDoneRejCom_Click" />
</div>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
code behind :
protected void btnBackRejCom_Click1(object sender, EventArgs e)
{
pnlRejCom.Visible = false;
pnlAppRej.Visible = true;
}
Hope this helps. Happy Coding..!!!
I have same problem so I have just added CausesValidation="False" then it works fine for me.so please add CausesValidation in btnBackRejCom button like as below
Please try it
<asp:Button ID="btnBackRejCom" runat="server" CausesValidation="False" CssClass="button" Text="Back" Style="margin-right: 20px;
margin-top: 10px" Width="100px" />
I think It works for you :)
I have this view in my asp.net application :
<asp:UpdatePanel ID="C_Compte" runat="server" UpdateMode="Conditional">
<ContentTemplate>
Métier:
<asp:TextBox ID="tbAddMetier" CssClass="Textboxes" Width="300px" Height="25px" runat="server"></asp:TextBox>
<asp:Button ID="btnAddMetier" runat="server" Text="Ajouter" CssClass="OffreEmploiSearch" OnClick="Button1_Click" />
<h4 style="font-weight: bold">Mes métiers</h4>
<asp:Repeater ID="rptrMetier" runat="server">
<ItemTemplate>
<div style="font: normal normal normal 14px/1.4em play, sans-serif; color: rgb(95, 94, 93); padding-left: 10px; line-height: 22px">
<strong><%# Eval("Lebelle") %></strong></a>
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/Design_Ressources/img/attachment.png" OnCommand="ImageButton1_Command" CommandArgument='<%# Eval("Lebelle") %>' />
</div>
</ItemTemplate>
</asp:Repeater>
</ContentTemplate>
</asp:UpdatePanel>
in the code behind
protected void ImageButton1_Command(object sender, CommandEventArgs e)
{
string newjob = e.CommandArgument.ToString().Split(',')[0];
}
Edit Data Binding
protected void Button1_Click(object sender, EventArgs e)
{
string newjob = tbAddMetier.Text;
Metier m = new Metier { Lebelle = newjob };
CurrentCandidat.Metier1.Add(m);
try
{
notrecontexte.SaveChanges();
}
catch
{
}
tbAddMetier.Text = "";
rptrMetier.DataSource = CurrentCandidat.Metier1;
rptrMetier.DataBind();
C_Compte.Update();
}
My problem is that the button clic event is never fired!!
What is the reason?
How can i fix my code?
Add Postback trigger for Button1 as mentioned below :
<asp:UpdatePanel ID="C_Compte" runat="server" UpdateMode="Conditional">
<ContentTemplate>
Métier:
<asp:TextBox ID="tbAddMetier" CssClass="Textboxes" Width="300px" Height="25px" runat="server"></asp:TextBox>
<asp:Button ID="btnAddMetier" runat="server" Text="Ajouter" CssClass="OffreEmploiSearch" OnClick="Button1_Click" />
<h4 style="font-weight: bold">Mes métiers</h4>
<asp:Repeater ID="rptrMetier" runat="server">
<ItemTemplate>
<div style="font: normal normal normal 14px/1.4em play, sans-serif; color: rgb(95, 94, 93); padding-left: 10px; line-height: 22px">
<strong><%# Eval("Lebelle") %></strong></a>
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/Design_Ressources/img/attachment.png" OnCommand="ImageButton1_Command" CommandArgument='<%# Eval("Lebelle") %>' />
</div>
</ItemTemplate>
</asp:Repeater>
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="btnAddMetier"/>
</Triggers>
</asp:UpdatePanel>
i got a task for creating leave application for the employees.. it contains 3 tabs one with apply leave which has
type for leave
description
begin date
end date
number of days
those begin and end date contains calendar extenders and once i select both dates , cursor should point on number of days textbox and it should calculate the total number of days leave will be taken... please help me sort this out..
i have tried this
cs
protected void BtnApply_Click(object sender, EventArgs e)
{
MTMSDTO objc = new MTMSDTO();
int Flag = 0;
LblLogdInUser.Text = Session["EmpName"].ToString();
objc.LoggedInUser = LblLogdInUser.Text;
objc.TypeofLeave = DrpTypeofLeave.SelectedItem.Text;
string date;
date = Convert.ToDateTime(TxtBeginDate.Text).ToString("dd/MM/yyyy");
DateTime dt = new DateTime();
dt = Convert.ToDateTime(date);
objc.BeginDate = dt;
objc.EndDate = Convert.ToDateTime(TxtEndDate.Text);
objc.Description = TxtDescription.Text;
objc.NumofDays = Convert.ToInt32(TxtNumofDays.Text);
//objc.EmpName = LblLogdInUser.Text;
int X = obj.InsertLeave(objc);
{
if (X >= 0)
{
Flag = 1;
}
else
{
Flag = 0;
}
}
if (Flag == 1)
{
LblSuccess.Visible = true;
LblSuccess.Text = "Data Added Successfully";
DrpTypeofLeave.ClearSelection();
TxtBeginDate.Text = "";
TxtEndDate.Text = "";
TxtDescription.Text = "";
TxtNumofDays.Text = "";
}
else
{
LblErr.Visible = true;
LblErr.Text = "Failed To Add Data!!!";
}
}
protected void TxtNumofDays_TextChanged1(object sender, EventArgs e)
{
MTMSDTO objc = new MTMSDTO();
TxtNumofDays.Text = Session["NumofDays"].ToString();
objc.NumofDays = Convert.ToInt32(TxtNumofDays.Text);
}
protected void TxtEndDate_TextChanged(object sender, EventArgs e)
{
DateTime BeginDate = Convert.ToDateTime(TxtBeginDate.Text);
DateTime EndDate = Convert.ToDateTime(TxtEndDate.Text);
TimeSpan diff = EndDate.Subtract(BeginDate);
TxtNumofDays.Text = diff.Days.ToString();
TxtNumofDays.Focus();
}
aspx
<asp:Panel ID="Panel1" runat="server" Height="567px" Width="858px">
<table style="width:100%; height: 587px;">
<tr>
<td class="style50">
</td>
<td class="style51">
<asp:TabContainer ID="TabContainer1" runat="server" ActiveTabIndex="0"
Height="550px" Width="833px">
<asp:TabPanel ID="TabLAP" runat="server" HeaderText="Leave Application">
<HeaderTemplate>
<span class="style40"><strong>Leave Application</strong></span>
</HeaderTemplate>
<ContentTemplate>
<table style="width:101%; height: 505px; margin-left: 0px;">
<tr>
<td class="style160" style="font-weight: 700;">
</td>
<td class="style161" style="font-weight: 700; ">
<asp:Label ID="LblLogdInUser" runat="server" BorderColor="#0061C1"
BorderWidth="1px" Font-Bold="True" Font-Names="Verdana" Font-Size="X-Small"
ForeColor="#0061C1" Height="23px" Visible="False" Width="123px"></asp:Label>
<asp:RoundedCornersExtender ID="LblLogdInUser_RoundedCornersExtender"
runat="server" BorderColor="Black" Enabled="True" Radius="4"
TargetControlID="LblLogdInUser"></asp:RoundedCornersExtender>
</td>
<td class="style162" style="font-weight: 700; ">
</td>
</tr>
<tr>
<td class="style159" style="font-weight: 700; ">
Type Of Leave:</td>
<td class="style156">
<asp:DropDownList ID="DrpTypeofLeave" runat="server"
AppendDataBoundItems="True" BorderColor="#0061C1" BorderWidth="1px"
Font-Bold="True" Font-Names="Verdana" Font-Size="X-Small" ForeColor="#0061C1"
Height="29px" onselectedindexchanged="DrpTypeofLeave_SelectedIndexChanged1"
style="text-align: left" Width="123px"><asp:ListItem Selected="True" Value="0">Please Select</asp:ListItem><asp:ListItem
Value="1">Sick Leave</asp:ListItem><asp:ListItem Value="2">Casual Leave</asp:ListItem><asp:ListItem
Value="3">Earned Leave</asp:ListItem>
</asp:DropDownList>
<asp:RoundedCornersExtender ID="DrpTypeofLeave_RoundedCornersExtender"
runat="server" BorderColor="Black" Enabled="True" Radius="4"
TargetControlID="DrpTypeofLeave"></asp:RoundedCornersExtender>
</td>
<td class="style141" style="font-weight: 700; ">
</td>
</tr>
<tr>
<td class="style146" style="font-weight: 700; ">
Description:</td>
<td class="style154" style="font-weight: 700; ">
<asp:TextBox ID="TxtDescription" runat="server" BorderColor="#0061C1"
BorderWidth="1px" Font-Bold="True" Font-Names="Verdana" Font-Size="X-Small"
ForeColor="#0061C1" Height="25px" style="text-align: left" TextMode="MultiLine"
Width="103px"></asp:TextBox>
<asp:RoundedCornersExtender ID="TxtDescription_RoundedCornersExtender"
runat="server" BorderColor="Black" Enabled="True" Radius="4"
TargetControlID="TxtDescription"></asp:RoundedCornersExtender>
</td>
<td class="style144" style="font-weight: 700; ">
</td>
</tr>
<tr>
<td class="style159" style="font-weight: 700; ">
Begin Date:</td>
<td class="style156" style="font-weight: 700; ">
<asp:TextBox ID="TxtBeginDate" runat="server" BorderColor="#0061C1"
BorderWidth="1px" Font-Bold="True" Font-Names="Verdana" Font-Size="X-Small"
ForeColor="#0061C1" Height="25px" style="text-align: left" Width="73px"></asp:TextBox>
<asp:ImageButton ID="ImageButton1" runat="server"
AlternateText="Click to show calendar" ImageUrl="Images/calendar.png" />
<asp:CalendarExtender ID="TxtBeginDate_CalendarExtender" runat="server"
Enabled="True" Format="dd/MM/yyyy" PopupButtonID="ImageButton1"
PopupPosition="Right" TargetControlID="TxtBeginDate"
TodaysDateFormat="dd/MM/yyyy"></asp:CalendarExtender>
<asp:RoundedCornersExtender ID="TxtBeginDate_RoundedCornersExtender"
runat="server" BorderColor="Black" Enabled="True" Radius="4"
TargetControlID="TxtBeginDate"></asp:RoundedCornersExtender>
<asp:CompareValidator ID="chkBeginDate" runat="server"
ControlToValidate="TxtBeginDate" Display="Dynamic"
ErrorMessage="You must supply a valid start date" ForeColor="Red"
Operator="DataTypeCheck" Type="Date" /><td class="style141"
style="font-weight: 700; ">
</td>
</td>
</tr>
<tr>
<td class="style159" style="font-weight: 700; ">
End Date:</td>
<td class="style156" style="font-weight: 700; ">
<asp:TextBox ID="TxtEndDate" runat="server" BorderColor="#0061C1"
BorderWidth="1px" Font-Bold="True" Font-Names="Verdana" Font-Size="X-Small"
ForeColor="#0061C1" Height="25px" ontextchanged="TxtEndDate_TextChanged"
style="text-align: left" Width="73px" AutoPostBack ="true"></asp:TextBox>
<asp:ImageButton ID="ImageButton2" runat="server"
AlternateText="Click to show calendar" ImageUrl="Images/calendar.png" />
<asp:CalendarExtender ID="TxtEndDate_CalendarExtender" runat="server"
Enabled="True" Format="dd/MM/yyyy" PopupButtonID="ImageButton2"
PopupPosition="Right" TargetControlID="TxtEndDate"
TodaysDateFormat="dd/MM/yyyy"></asp:CalendarExtender>
<asp:RoundedCornersExtender ID="TxtEndDate_RoundedCornersExtender"
runat="server" BorderColor="Black" Enabled="True" Radius="4"
TargetControlID="TxtEndDate"></asp:RoundedCornersExtender>
<asp:CompareValidator ID="chkEndDate" runat="server"
ControlToValidate="TxtEndDate" Display="Dynamic"
ErrorMessage="You must supply a valid end date" ForeColor="Red"
Operator="DataTypeCheck" Type="Date" /><br />
<asp:CompareValidator ID="cmpBeginAndEndDates" runat="server"
ControlToCompare="TxtBeginDate" ControlToValidate="TxtEndDate"
Display="Dynamic" ErrorMessage="The end date must be after the start date"
ForeColor="Red" Operator="GreaterThan" /></td>
<td class="style141" style="font-weight: 700; ">
</td>
</tr>
<tr>
<td class="style159" style="font-weight: 700; ">
Number of Days:</td>
<td class="style156" style="font-weight: 700; ">
<asp:TextBox ID="TxtNumofDays" runat="server" BorderColor="#0061C1"
BorderWidth="1px" Font-Bold="True" Font-Names="Verdana" Font-Size="X-Small"
ForeColor="#0061C1" Height="25px" ontextchanged="TxtNumofDays_TextChanged1"
style="text-align: left" Width="73px"></asp:TextBox>
<asp:RoundedCornersExtender ID="TxtNumofDays_RoundedCornersExtender"
runat="server" BorderColor="Black" Enabled="True" Radius="4"
TargetControlID="TxtNumofDays"></asp:RoundedCornersExtender>
</td>
<td class="style141" style="font-weight: 700; ">
</td>
</tr>
<tr>
<td class="style164" style="font-weight: 700; ">
<br />
<asp:Label ID="LblSuccess" runat="server" Font-Bold="True" Font-Names="Verdana"
Font-Size="X-Small" ForeColor="#009933" Height="14px" style="text-align: right"
Visible="False"></asp:Label>
<br />
<asp:Label ID="LblErr" runat="server" Font-Bold="True" Font-Names="Verdana"
Font-Size="X-Small" ForeColor="#CC0000" Height="14px" Visible="False"></asp:Label>
</td>
<td class="style163" style="font-weight: 700; ">
<asp:Button ID="BtnApply" runat="server" BackColor="White"
BorderColor="#0061C1" BorderWidth="1px" CssClass="ButtonClass" Font-Bold="True"
Font-Names="Verdana" Font-Size="Small" ForeColor="#0061C1" Height="21px"
OnClick="BtnApply_Click" Text="Apply" Width="65px" />
<asp:RoundedCornersExtender ID="BtnApply_RoundedCornersExtender1"
runat="server" BorderColor="Black" Enabled="True" Radius="4"
TargetControlID="BtnApply"></asp:RoundedCornersExtender>
<asp:Button ID="BtnCancel" runat="server" BackColor="White"
BorderColor="#0061C1" BorderWidth="1px" CssClass="ButtonClass" Font-Bold="True"
Font-Names="Verdana" Font-Size="Small" ForeColor="#0061C1" Height="21px"
OnClick="BtnCancel_Click" Text="Cancel" Width="65px" />
<asp:RoundedCornersExtender ID="BtnCancel_RoundedCornersExtender"
runat="server" BorderColor="Black" Enabled="True" Radius="4"
TargetControlID="BtnCancel"></asp:RoundedCornersExtender>
</td>
<td class="style165" style="font-weight: 700; ">
</td>
</tr>
<tr>
<td class="style159" style="font-weight: 700; ">
</td>
<td class="style156" style="font-weight: 700; ">
</td>
<td class="style141" style="font-weight: 700; ">
</td>
</tr>
</table>
</ContentTemplate>
</asp:TabPanel>
</asp:Panel>
I'm getting the number of days value in my database but its not showing in the textbox and cursor is not pointing too to the textbox of number of days wen i run the project..
I think you are taking the hard way out there is a much easier way of implementing what you are trying to do in ASP.net. First it would require the use of jQuery UI (date-picker). I came up with a pure JavaScript and HTML5 solution to your problem. I think you are going a bit over board with the post back of the data just so you can get the date out of it.
Note: I am not doing any validation nor have I made this specific towards your application.
Here is my solution:
CSS style, just to make things okay looking ;)
<!-- link to the jQuery UI CSS -->
<link href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<style>
#employee_form {
width: 350px;
background: #f0e68c;
padding: .2em;
}
li {
list-style: none;
font-weight: bold;
}
li input {
float: right;
}
</style>
aspx page
<form id="form1" runat="server">
<div id="employee_form">
<ul>
<li>
<p>
<asp:Label ID="Label1" runat="server" Text="Type of leave"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</p>
</li>
<li>
<p>
<asp:Label ID="Label6" runat="server" Text="Description"></asp:Label>
<asp:TextBox ID="TextBox6" runat="server"></asp:TextBox>
</p>
</li>
<li>
<p>
<asp:Label ID="Label2" runat="server" Text="Begin Date"></asp:Label>
<asp:TextBox ID="beginDate" runat="server"></asp:TextBox>
</p>
</li>
<li>
<p>
<asp:Label ID="Label3" runat="server" Text="End Date"></asp:Label>
<asp:TextBox ID="endDate" runat="server"></asp:TextBox>
</p>
</li>
<li>
<p>
<asp:Label ID="Label4" runat="server" Text="Number of Days"></asp:Label>
<asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
</p>
</li>
<asp:Button ID="Button1" runat="server" Text="Submit" OnClick="Button1_Click" />
</ul>
</div>
</form>
JavaScript
<!-- link to the latest jquery -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<!-- link to the jQuery UI -->
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script>
(function () {
$('.date').datepicker();
var resultDate = "";
$('.date').on('change', function () {
var beginDate = $('#beginDate').val();
var endDate = $("#endDate").val();
if (beginDate != "" && endDate != "") {
beginDate = new Date(beginDate);
endDate = new Date(endDate);
resultDate = endDate.getDate() - beginDate.getDate();
}
$("#days").val(resultDate + " ");
});
})();
</script>
cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace _Web_StackoverFlow_Question_Test_Code
{
public partial class EmployeeLeaveForm : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
// Submit the data to the database
}
}
}
End of solution
Feel free to ask me any question on twitter #muhammad_khan40.
Thanks, let me know if the solution helped with your problem.
cs code:
protected void TxtNumofDays_TextChanged1(object sender, EventArgs e)
{
MTMSDTO objc = new MTMSDTO();
TxtNumofDays.Text = Session["NumofDays"].ToString();
objc.NumofDays = Convert.ToInt32(TxtNumofDays.Text);
}
protected void TxtEndDate_TextChanged(object sender, EventArgs e)
{
DateTime BeginDate = Convert.ToDateTime(TxtBeginDate.Text);
DateTime EndDate = Convert.ToDateTime(TxtEndDate.Text);
TimeSpan diff = EndDate.Subtract(BeginDate);
TxtNumofDays.Text = diff.Days.ToString();
TxtNumofDays.Focus();
}
aspx code:
<asp:TextBox ID="TxtBeginDate" runat="server" BorderColor="#0061C1"
BorderWidth="1px" Font-Bold="True" Font-Names="Verdana" Font-Size="X-Small"
ForeColor="#0061C1" Height="25px" style="text-align: left" Width="73px"></asp:TextBox>
<asp:ImageButton ID="ImageButton1" runat="server"
AlternateText="Click to show calendar" ImageUrl="Images/calendar.png" />
<asp:CalendarExtender ID="TxtBeginDate_CalendarExtender" runat="server"
Enabled="True" Format="dd/MM/yyyy" PopupButtonID="ImageButton1"
PopupPosition="Right" TargetControlID="TxtBeginDate"
TodaysDateFormat="dd/MM/yyyy"> </asp:CalendarExtender>
<asp:RoundedCornersExtender ID="TxtBeginDate_RoundedCornersExtender"
runat="server" BorderColor="Black" Enabled="True" Radius="4"
TargetControlID="TxtBeginDate"></asp:RoundedCornersExtender>
<asp:CompareValidator ID="chkBeginDate" runat="server"
ControlToValidate="TxtBeginDate" Display="Dynamic"
ErrorMessage="You must supply a valid start date" ForeColor="Red"
Operator="DataTypeCheck" Type="Date" />
<asp:TextBox ID="TxtEndDate" runat="server" BorderColor="#0061C1"
BorderWidth="1px" Font-Bold="True" Font-Names="Verdana" Font-Size="X-Small"
ForeColor="#0061C1" Height="25px" ontextchanged="TxtEndDate_TextChanged"
style="text-align: left" Width="73px" AutoPostBack ="true"></asp:TextBox>
<asp:ImageButton ID="ImageButton2" runat="server"
AlternateText="Click to show calendar" ImageUrl="Images/calendar.png" />
<asp:CalendarExtender ID="TxtEndDate_CalendarExtender" runat="server"
Enabled="True" Format="dd/MM/yyyy" PopupButtonID="ImageButton2"
PopupPosition="Right" TargetControlID="TxtEndDate"
TodaysDateFormat="dd/MM/yyyy"></asp:CalendarExtender>
<asp:RoundedCornersExtender ID="TxtEndDate_RoundedCornersExtender"
runat="server" BorderColor="Black" Enabled="True" Radius="4"
TargetControlID="TxtEndDate"></asp:RoundedCornersExtender>
<asp:CompareValidator ID="chkEndDate" runat="server"
ControlToValidate="TxtEndDate" Display="Dynamic"
ErrorMessage="You must supply a valid end date" ForeColor="Red"
Operator="DataTypeCheck" Type="Date" /><br />
<asp:CompareValidator ID="cmpBeginAndEndDates" runat="server"
ControlToCompare="TxtBeginDate" ControlToValidate="TxtEndDate"
Display="Dynamic" ErrorMessage="The end date must be after the start date"
ForeColor="Red" Operator="GreaterThan" />