hide textbox by onselectIndexChange event - c#

In my website I have a dropdown list with 2 values. I am trying to write this code to hide textbox by onselectIndexChange event without refreshing the page.
for this goal I used Update panel but on dropDownList select there is no change in textboxs visibility.
my codes:
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<table dir="rtl">
<tr>
<td>
<asp:Label ID="Label1" runat="server" Text="شخص :"></asp:Label></td>
<td>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DropDownList ID="DropDownList1" EnableViewState="true" AutoPostBack="true" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem Selected="True">حقیقی</asp:ListItem>
<asp:ListItem>حقوقی</asp:ListItem>
</asp:DropDownList>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="DropDownList1" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
</td>
</tr>
<asp:Panel ID="pnlname" runat="server">
<tr>
<td>
<asp:Label ID="Label2" runat="server" Text="نام و نام خانوادگی : "></asp:Label>
</td>
<td>
<asp:TextBox ID="txtname" runat="server" Width="415px"></asp:TextBox>
</td>
</tr>
</asp:Panel>
<asp:Panel ID="pnlMname" runat="server">
<tr>
<td>
<asp:Label ID="Label3" runat="server" Text="نام و نام خانوادگی مسئول : "></asp:Label>
</td>
<td>
<asp:TextBox ID="txtmname" Width="415px" runat="server"></asp:TextBox>
</td>
</tr>
</asp:Panel>
<tr>
<td>
<asp:Label ID="Label4" runat="server" Text="شماره قرارداد : "></asp:Label>
</td>
<td>
<asp:TextBox ID="txtIdgharardad" Width="415px" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label7" runat="server" Text="علت درخواست اعزام کارشناس : "></asp:Label>
</td>
<td>
<asp:TextBox ID="txtellat" Width="415px" runat="server" Height="194px" TextMode="MultiLine"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label5" runat="server" Text="شماره همراه : "></asp:Label>
</td>
<td>
<asp:TextBox ID="txtNumber" Width="415px" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label6" runat="server" Text="شماره ثابت : "></asp:Label>
</td>
<td>
<asp:TextBox ID="txtSnumber" Width="415px" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="ثبت درخواست" />
</td>
<td> </td>
</tr>
</table>
.cs file:
protected void Page_Load(object sender, EventArgs e)
{
pnlMname.Visible = false;
}
protected void Button1_Click(object sender, EventArgs e)
{
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
if (DropDownList1.SelectedValue == "حقیقی")
{
pnlMname.Visible = false;
pnlname.Visible = true;
}
else if (DropDownList1.SelectedValue == "حقوقی")
{
pnlname.Visible = false;
pnlMname.Visible = true;
}
}

Try Like This:
Use your All code Inside Update Panels
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
// All Controls Placed Here
</ContentTemplate><Triggers>
</Triggers> </asp:UpdatePanel>
By default it will use Asynchronous postback
Code:
<asp:Label ID="Label1" runat="server" Text="شخص :"></asp:Label></td>
<td>
<asp:DropDownList ID="DropDownList1" EnableViewState="true" AutoPostBack="true" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem Selected="True">حقیقی</asp:ListItem>
<asp:ListItem>حقوقی</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<asp:Panel ID="pnlname" runat="server">
<tr>
<td>
<asp:Label ID="Label2" runat="server" Text="نام و نام خانوادگی : "></asp:Label>
</td>
<td>
<asp:TextBox ID="txtname" runat="server" Width="415px"></asp:TextBox>
</td>
</tr></asp:Panel>
<asp:Panel ID="pnlMname" runat="server">
<tr>
<td>
<asp:Label ID="Label3" runat="server" Text="نام و نام خانوادگی مسئول : "></asp:Label>
</td>
<td>
<asp:TextBox ID="txtmname" Width="415px" runat="server"></asp:TextBox>
</td>
</tr></asp:Panel>
<tr>
<td>
<asp:Label ID="Label4" runat="server" Text="شماره قرارداد : "></asp:Label>
</td>
<td>
<asp:TextBox ID="txtIdgharardad" Width="415px" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label7" runat="server" Text="علت درخواست اعزام کارشناس : "></asp:Label>
</td>
<td>
<asp:TextBox ID="txtellat" Width="415px" runat="server" Height="194px" TextMode="MultiLine"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label5" runat="server" Text="شماره همراه : "></asp:Label>
</td>
<td>
<asp:TextBox ID="txtNumber" Width="415px" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label6" runat="server" Text="شماره ثابت : "></asp:Label>
</td>
<td>
<asp:TextBox ID="txtSnumber" Width="415px" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="ثبت درخواست" />
</td>
<td>
</td>
</tr>
</table>
</ContentTemplate><Triggers>
</Triggers> </asp:UpdatePanel>

Related

Change table row text and bgcolor on a listview value asp.net C

I have a listview and I am trying to change the text color and background color depending on the value of "callswaiting". This is written in C#.
I am trying to accomplish this:
If(Eval("availableAgents") < 1); Then
; If(Eval("callsWaiting" > 2) ,Then );
{
tblSheet.Style.Add("color", "black");
tblSheet.Style.Add("background-color", "red");
}
Else;
{
tblSheet.Style.Add("color", "black");
tblSheet.Style.Add("background-color", "orange");
}
End If;
Else;
{
tblSheet.Style.Add("color", "white");
tblSheet.Style.Add("background-color", "green");
}
End If;
Just stumped on how to update this to ASPX and C#.
My ASPX code is:
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
</Triggers>
<ContentTemplate>
<asp:ListView ID="ListView1" runat="server" DataSourceID="con_csq_agentDB" onitemdatabound="ListView1_ItemDataBound">
<AlternatingItemTemplate>
<tr id="MainTableRow" style="background-color: #ADADAD;">
<td style="background-color: gray; color: whitesmoke;">
<asp:Label ID="csqnameLabel" runat="server" Text='<%# Eval("csqname") %>' />
</td>
<td>
<asp:Label ID="callswaitingLabel" runat="server" Text='<%# Eval("callswaiting") %>' />
</td>
<td>
<asp:Label ID="convoldestcontactLabel" runat="server" Text='<%# Eval("convoldestcontact") %>' />
</td>
<td>
<asp:Label ID="loggedinagentsLabel" runat="server" Text='<%# Eval("loggedinagents") %>' />
</td>
<td>
<asp:Label ID="availableagentsLabel" runat="server" Text='<%# Eval("availableagents") %>' />
</td>
<td>
<asp:Label ID="talkingagentsLabel" runat="server" Text='<%# Eval("talkingagents") %>' />
</td>
</tr>
</AlternatingItemTemplate>
<ItemTemplate>
<tr id="MainTableRow" style="background-color: #DCDCDC; color: #000000;">
<td style="background-color: gray; color: whitesmoke;">
<asp:Label ID="csqnameLabel" runat="server" Text='<%# Eval("csqname") %>' />
</td>
<td>
<asp:Label ID="callswaitingLabel" runat="server" Text='<%# Eval("callswaiting") %>' />
</td>
<td>
<asp:Label ID="convoldestcontactLabel" runat="server" Text='<%# Eval("convoldestcontact") %>' />
</td>
<td>
<asp:Label ID="loggedinagentsLabel" runat="server" Text='<%# Eval("loggedinagents") %>' />
</td>
<td>
<asp:Label ID="availableagentsLabel" runat="server" Text='<%# Eval("availableagents") %>' />
</td>
<td>
<asp:Label ID="talkingagentsLabel" runat="server" Text='<%# Eval("talkingagents") %>' />
</td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table id="itemPlaceholderContainer" runat="server" data-height='100%'>
<tr runat="server" style="background-color: #113C77; color: #000000;">
<th runat="server"></th>
<th runat="server">Calls waiting</th>
<th runat="server">Current Wait</th>
<th runat="server">Agents Logged in</th>
<th runat="server">Ready</th>
<th runat="server">Talking</th>
</tr>
<tr id="itemPlaceholder" runat="server">
</tr>
</table>
</LayoutTemplate>
My C# code is:
public partial class csq_agent : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
ListView1.DataSourceID = con_csq_agentDB.UniqueID;
}
}
protected void ListView1_ItemDataBound(object sender, ListViewItemEventArgs e)
{
if (e.Item.ItemType == ListViewItemType.DataItem)
{
ListViewDataItem dataitem = (ListViewDataItem)e.Item;
int callswaiting = (int)DataBinder.Eval(dataitem.DataItem, "callswaiting");
if (callswaiting == 3)
{
HtmlTableRow cell = (HtmlTableRow)e.Item.FindControl("MainTableRow");
cell.BgColor = "Red";
}
}
}

FindControl returns empty textbox object / null

I have a html table on a page:
<table id="tblMain" runat="server" style="margin-left: auto; margin-right: auto;">
<tr>
<td>
Safety
</td>
<td>
<asp:TextBox ID="txtSafety" Width="400px" ReadOnly="true" TextMode="MultiLine" runat="server"></asp:TextBox>
</td>
<td>
<asp:Button ID="btnSafety" runat="server" Width="150px" Text="Edit"
OnClick="Edit_Text" CommandArgument="0" />
</td>
</tr>
<tr>
<td>
Environment
</td>
<td>
<asp:TextBox ID="txtEnvironment" Width="400px" ReadOnly="true" TextMode="MultiLine" runat="server"></asp:TextBox>
</td>
<td>
<asp:Button ID="bntEnvironment" Width="150px" runat="server" Text="Edit"
OnClick="Edit_Text" CommandArgument="1" />
</td>
</tr>
<tr>
<td>
Quality
</td>
<td>
<asp:TextBox ID="txtQuality" Width="400px" ReadOnly="true" TextMode="MultiLine" runat="server"></asp:TextBox>
</td>
<td>
<asp:Button ID="btnQuality" Width="150px" runat="server" Text="Edit"
OnClick="Edit_Text" CommandArgument="2" />
</td>
</tr>
<tr>
<td>
Ferrous System
</td>
<td>
<asp:TextBox ID="txtFerrousSystem" Width="400px" ReadOnly="true" TextMode="MultiLine"
runat="server"></asp:TextBox>
</td>
<td>
<asp:Button ID="btnFerrousSystem" Width="150px" runat="server" Text="Edit"
OnClick="Edit_Text" CommandArgument="3" />
</td>
</tr>
<tr>
<td>
Coke System
</td>
<td>
<asp:TextBox ID="txtCokeSystem" Width="400px" ReadOnly="true" TextMode="MultiLine"
runat="server"></asp:TextBox>
</td>
<td>
<asp:Button ID="btnCokeSystem" Width="150px" runat="server" Text="Edit"
OnClick="Edit_Text" CommandArgument="4" />
</td>
</tr>
<tr>
<td>
Coal Yards
</td>
<td>
<asp:TextBox ID="txtCoalYards" Width="400px" ReadOnly="true" TextMode="MultiLine"
runat="server"></asp:TextBox>
</td>
<td>
<asp:Button ID="btnCoalYards" Width="150px" runat="server" Text="Edit"
OnClick="Edit_Text" CommandArgument="5" />
</td>
</tr>
<tr>
<td>
Screenhouse
</td>
<td>
<asp:TextBox ID="txtScreenhouse" Width="400px" ReadOnly="true" TextMode="MultiLine"
runat="server"></asp:TextBox>
</td>
<td>
<asp:Button ID="btnScreenhouse" Width="150px" runat="server" Text="Edit"
OnClick="Edit_Text" CommandArgument="6" />
</td>
</tr>
<tr>
<td>
Process Plant
</td>
<td>
<asp:TextBox ID="txtProcessPlant" Width="400px" ReadOnly="true" TextMode="MultiLine"
runat="server"></asp:TextBox>
</td>
<td>
<asp:Button ID="btnProcessPlant" Width="150px" runat="server" Text="Edit"
OnClick="Edit_Text" CommandArgument="7" />
</td>
</tr>
<tr>
<td>
New Mill
</td>
<td>
<asp:TextBox ID="txtNewMill" Width="400px" ReadOnly="true" TextMode="MultiLine" runat="server"></asp:TextBox>
</td>
<td>
<asp:Button ID="btnNewMill" Width="150px" runat="server" Text="Edit"
OnClick="Edit_Text" CommandArgument="8" />
</td>
</tr>
<tr>
<td>
Streamphases
</td>
<td>
<asp:TextBox ID="txtStreamphases" Width="400px" ReadOnly="true" TextMode="MultiLine"
runat="server"></asp:TextBox>
</td>
<td>
<asp:Button ID="btnStreamphases" Width="150px" runat="server" Text="Edit"
OnClick="Edit_Text" CommandArgument="9" />
</td>
</tr>
<tr>
<td>
Furnace Silos Injection
</td>
<td>
<asp:TextBox ID="txtFurnaceSilosInjection" Width="400px" ReadOnly="true" TextMode="MultiLine"
runat="server"></asp:TextBox>
</td>
<td>
<asp:Button ID="btnFurnaceSilosInjection" Width="150px" runat="server" Text="Edit"
OnClick="Edit_Text" CommandArgument="10" />
</td>
</tr>
<tr>
<td>
CompressedAir
</td>
<td>
<asp:TextBox ID="txtCompressedAir" Width="400px" ReadOnly="true" TextMode="MultiLine"
runat="server"></asp:TextBox>
</td>
<td>
<asp:Button ID="btnCompressedAir" Width="150px" runat="server" Text="Edit"
OnClick="Edit_Text" CommandArgument="11" />
</td>
</tr>
<tr>
<td>
Planned Maintenance
</td>
<td>
<asp:TextBox ID="txtPlannedMaintenance" Width="400px" ReadOnly="true" TextMode="MultiLine"
runat="server"></asp:TextBox>
</td>
<td>
<asp:Button ID="btnPlannedMaintenance" Width="150px" runat="server" Text="Edit"
OnClick="Edit_Text" CommandArgument="12" />
</td>
</tr>
<tr>
<td>
Notifications Raised
</td>
<td>
<asp:TextBox ID="txtNotificationsRaised" Width="400px" ReadOnly="true" TextMode="MultiLine"
runat="server"></asp:TextBox>
</td>
<td>
<asp:Button ID="btnNotificationsRaised" Width="150px" runat="server" Text="Edit"
OnClick="Edit_Text" CommandArgument="13" />
</td>
</tr>
<tr>
<td>
Manning
</td>
<td>
<asp:TextBox ID="txtManning" Width="400px" ReadOnly="true" TextMode="MultiLine" runat="server"></asp:TextBox>
</td>
<td>
<asp:Button ID="btnManning" Width="150px" runat="server" Text="Edit"
OnClick="Edit_Text" CommandArgument="14" />
</td>
</tr>
<tr>
<td>
ShiftHandover
</td>
<td>
<asp:TextBox ID="txtShiftHandover" Width="400px" ReadOnly="true" TextMode="MultiLine"
runat="server" OnClick="Edit_Text"></asp:TextBox>
</td>
<td>
<asp:Button ID="btnShiftHandover" Width="150px" runat="server" Text="Edit"
OnClick="Edit_Text" CommandArgument="15" />
</td>
</tr>
</table>
When the button is pressed the following method is called:
protected void Edit_Text(object sender, EventArgs e)
{
Button btn = sender as Button;
if (btn != null)
{
editField = btn.ID.Replace("btn", "");
btn.Visible = false;
//Getting and storing rowindex
TextBox txt = this.FindControl("txt" + editField) as TextBox;
txt.ReadOnly = false;
txt.BackColor = System.Drawing.ColorTranslator.FromHtml("#FFFFB2");
txt.Focus();
comment = txt.Text;
//Further methods unnecessary for this question
}
}
As you can see, the prefix is stripped from the controls and then added in when necessary to find the right control at the point, therefore the string for the FindControl method is correct and should return a a TextBox.
However, by stepping through I can see that it is passing an empty TextBox instance rather than the expected result or a null.
I have already tried the findcontrol function on the table itself, I used 'this' as a second check but both yielded the same results.
I suspect the html table is a problem as in another method I am having issues finding a button manually in the html table:
Button editbtn = tblMain.Rows[GetRowIndex(hdnRowIndex.Value)].Cells[2].Controls[0] as Button;
Which is returning a null despite there always being a cell button in that cell for each row
EDIT - Here is the binding that is performed
private void bindData(DataTable dt)
{
if (dt.Rows.Count > 0)
{
foreach (DataColumn col in dt.Columns)
{
TextBox txt = tblMain.FindControl("txt" + col.ColumnName) as TextBox;
if (txt != null)
{
txt.Text = dt.Rows[0][col].ToString();
}
}
}
}
Your problem is here:
this.FindControl("txt" + editField) as TextBox;
FindControl is not recursive and can only find immediate children of the control it was called on. Here you are calling it of the page instance, so it only seeks through immediate children of the page in the control tree (presumably this is only a form element).
What you need to do is to pick a server-side control right above your textboxes/buttons and run FindControl of it. For instance, let's say it is your table, which is declared as:
<table>
<%--...all the content from the post goes here...--%>
</table>
Make this table server-side:
<table id="TheTable" runat="server">
and then call FindControl on this table:
TextBox txt = TheTable.FindControl("txt" + editField) as TextBox;
You can of course keep the table client-side, and use some control that wraps this table. Just make sure that in between your control and the textbox in question there are no other server-side controls.
<table style="width:100%; margin-left:auto; margin-right:auto;" id="tblTst" runat="server">
<tr>
<td>
<h2>
Vehicle Information
<asp:Label ID="lblTest" Text="THis is a Test" ForeColor="Salmon" runat="server" />
<asp:Button ID="btnTest" CommandArgument="0" OnClick="btnTest_click" runat="server" Text="Test" />
</h2>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblTst2" Text="This is also a Test" ForeColor="Salmon" runat="server" />
<asp:Button ID="btnTest2" CommandArgument="1" OnClick="btnTest_click" runat="server" Text="Test" />
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblMsg" runat="server" />
</td>
</tr>
</table>
protected void btnTest_click(object sender, EventArgs e)
{
Button btn = sender as Button;
string comment = "";
string editField = "";
if (btn != null)
{
editField = btn.ID.Replace("btn", "");
btn.Visible = false;
//Getting and storing rowindex
foreach(HtmlTableCell cl in tblTst.Rows[Convert.ToInt32(btn.CommandArgument)].Cells)
{
foreach (Control ctrl in cl.Controls)
{
if(ctrl is Label)
{
Label txt = new Label();
txt = ctrl as Label;
txt.BackColor = System.Drawing.ColorTranslator.FromHtml("#FFFFB2");
txt.Focus();
comment = txt.Text;
lblMsg.Text = comment;
return;
}
}
}
//Further methods unnecessary for this question
}
}
}
This is what I came up with, this does work; however it is a fairly dirty way to do this, I'm sure you can clean it up quite a bit. This is only intended as a starting point. The big different is that you need to look in the cell for the control not in the table or page, also the cell is an htmltable cell not just a table cell.

error creating control , Unable to create type 'cc1: TabContainer', could not load file or assembly System.Web.extension, Version=1.0.61025.0'

error creating control , Unable to create type 'cc1: TabContainer', could not load file or assembly System.Web.extension, Version=1.0.61025.0'
The system cannot find the file specified
im getting this error . can u tell me where im wrong? why cant i see my design in aspx ?
code
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<cc1:TabContainer runat="server" ID="Tab_Continer" ActiveTabIndex="0">
<cc1:TabPanel ID="TabPnl_Project" runat="server">
<HeaderTemplate>
Keyword Position</HeaderTemplate>
<ContentTemplate>
<table>
<tr>
<td>
<asp:Label ID="lbl_Project" runat="server" Text="Project"></asp:Label>
</td>
<td>
<asp:DropDownList ID="ddlProject" runat="server" OnSelectedIndexChanged="ddlProject_SelectedIndexChanged"
AutoPostBack="true">
</asp:DropDownList>
<asp:RequiredFieldValidator Display="Dynamic" ID="RequiredFieldValidator3" runat="server"
ErrorMessage="*" ControlToValidate="ddlProject" ValidationGroup="ValPos"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblLkeyword" runat="server" Text="Keyword"></asp:Label>
</td>
<td>
<asp:DropDownList ID="ddlKeyword" runat="server" OnSelectedIndexChanged="ddlKeyword_SelectedIndexChanged"
AutoPostBack="true">
</asp:DropDownList>
<asp:RequiredFieldValidator Display="Dynamic" ID="RequiredFieldValidator2" runat="server"
ErrorMessage="*" ControlToValidate="ddlKeyword" ValidationGroup="ValPos"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblPos" runat="server" Text="Position"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtPostion" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator Display="Dynamic" ID="RequiredFieldValidator1" runat="server"
ErrorMessage="*" ControlToValidate="txtPostion" ValidationGroup="ValPos"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ControlToValidate="txtPostion"
ValidationExpression="^[0-9]{0,3}$" ErrorMessage="*" ValidationGroup="ValPos"
ToolTip="Enter only numeric values" Display="Dynamic"></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lbl_Date" runat="server" Text="Date"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtDate" runat="server"></asp:TextBox>
<cc1:CalendarExtender ID="Ajax_Calend" runat="server" TargetControlID="txtDate">
</cc1:CalendarExtender>
<asp:RequiredFieldValidator Display="Dynamic" ID="Valid_Req_DtFrm" runat="server"
ErrorMessage="*" ControlToValidate="txtDate" ValidationGroup="ValPos"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
</td>
<td align="left">
<asp:Button ID="btn_Submit" runat="server" Text="Submit" ValidationGroup="ValPos"
OnClick="btn_Submit_Click" CssClass="button" />
</td>
</tr>
<tr>
<td>
</td>
<td align="left">
<asp:Label ID="LblMsg" runat="server" Font-Bold="true"></asp:Label>
</td>
</tr>
</table>
</ContentTemplate>
</cc1:TabPanel>
<cc1:TabPanel ID="Tab_Update" runat="server">
<HeaderTemplate>
Traffic</HeaderTemplate>
<ContentTemplate>
<asp:UpdatePanel ID="update12" runat="server">
<ContentTemplate>
<table>
<tr>
<td>
<asp:Label ID="lblProject" runat="server" Text="Project"></asp:Label>
</td>
<td>
<asp:DropDownList ID="ddl_Project" runat="server">
</asp:DropDownList>
<asp:RequiredFieldValidator Display="Dynamic" ID="RequiredFieldValidator4" runat="server"
ErrorMessage="*" ControlToValidate="ddl_Project" ValidationGroup="ValTraffic"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblTraffic" runat="server" Text="Traffic"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtTarffic" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator Display="Dynamic" ID="RequiredFieldValidator5" runat="server"
ErrorMessage="*" ControlToValidate="txtTarffic" ValidationGroup="ValTraffic"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="txtTarffic"
ValidationExpression="^[0-9]{0,5}$" ErrorMessage="*" ToolTip="Enter only numeric values"
ValidationGroup="ValTraffic" Display="Dynamic"></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label1" runat="server" Text="Date"></asp:Label>
</td>
<td>
<asp:TextBox ID="Txt_Date" runat="server"></asp:TextBox>
<cc1:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="Txt_Date">
</cc1:CalendarExtender>
<asp:RequiredFieldValidator Display="Dynamic" ID="RequiredFieldValidator6" runat="server"
ErrorMessage="*" ControlToValidate="Txt_Date" ValidationGroup="ValTraffic"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
</td>
<td align="left">
<asp:Button ID="btnSave" runat="server" ValidationGroup="ValTraffic" Text="Submit"
OnClick="btnSave_Click" CssClass="button" />
</td>
</tr>
<tr>
<td>
</td>
<td align="left">
<asp:Label ID="lbl_Msg" runat="server" Font-Bold="true"></asp:Label>
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</ContentTemplate>
</cc1:TabPanel>
</cc1:TabContainer>

Showing comments without reloading page

The code below get me a comment , puts it in the database and then waits for a page reload to show the comment. How can i make the submited comment to be shown right after it has been posted along with the new ones ? This is the code that does the stuff :
Layout:
<table>
<tr>
<td colspan="2">All Comments</td>
<td>
&nbsp
</td>
</tr>
<tr> <td colspan="2"> </td></tr>
<tr>
<td>
<asp:Repeater ID="Repeater1" runat="server" ItemType="SiteStiri.Models.Comments" SelectMethod="GetComments" >
<ItemTemplate>
<table>
<tr>
<td colspan="2">
<asp:Label id="lblDate" runat="server" Text='<%# Item.ReleaseDate %>'></asp:Label>
</td>
</tr>
<tr>
<td colspan="3">
<asp:Label ID="lblComment" runat="server" Text='<%# Item.Comment %>'>
</asp:Label>
</td>
</tr>
</table>
</ItemTemplate>
<SeparatorTemplate>
<hr />
</SeparatorTemplate>
<AlternatingItemTemplate>
<table>
<tr>
<td colspan="2">
<asp:Label id="Label1" runat="server" Text='<%# Item.ReleaseDate %>'></asp:Label>
</td>
</tr>
<tr>
<td colspan="3">
<asp:Label ID="Label2" runat="server" Text='<%# Item.Comment %>'>
</asp:Label>
</td>
</tr>
</table>
</AlternatingItemTemplate>
</asp:Repeater>
</td>
</tr>
</table>
</td>
</tr>
<td>
<table>
<tr>
<td colspan="2" >Add Your Comment</td>
</tr>
<tr>
<td colspan="2">
<asp:Label ID="lblStatus" runat="server" Visible="False"></asp:Label>
</td>
<td>
&nbsp
</td>
</tr>
<tr>
<td colspan="2">
<asp:TextBox ID="txtcomment" runat="server" TextMode="MultiLine">
</asp:TextBox>
</td>
<td>
&nbsp
</td>
</tr>
<tr>
<td>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" />
</td>
<td>
&nbsp
</td>
</tr>
</table>
</table>
</td>
</tr>
</table>
Code Behind:
public void fnSubmitComment()
{
AddComment cmt = new AddComment();
String x = Request.QueryString["newsID"].ToString();
int y = Convert.ToInt32(x);
bool addSucces = cmt.Addcomment( y , txtcomment.Text);
if (addSucces)
{
lblStatus.Text = "Your Comment has been Added Successfully.";
}
else
{
lblStatus.Text = "Your Comment has not been Added.";
}
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
fnSubmitComment();
}
public IQueryable<Comments> GetComments()
{
var _db = new SiteStiri.Models.CommentsContext();
IQueryable<Comments> query = _db.Comments;
String x = Request.QueryString["newsID"].ToString();
int y = Convert.ToInt32(x);
query = query.Where(p => p.NewsID == y);
return query;
}
I heard i can do that with ajax ? (My knowledge about ajax is 0 currently) Any tips on how i can do this ?
You must wrapper you repeater in an updatepanel,
set UpdateMode="Conditional" and add a trigger on btnSubmit so when click the button the update the repeater with the normal page life cycle
Remember to bind the repeater after that you add the commet in the codebehind and must be present in your page a ScriptManager control
more or less thus
<asp:ScriptManager runat="server" />
<table>
<tr>
<td colspan="2">All Comments</td>
<td>&nbsp
</td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td>
<asp:UpdatePanel runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Repeater ID="Repeater1" runat="server" ItemType="SiteStiri.Models.Comments" SelectMethod="GetComments">
<ItemTemplate>
<table>
<tr>
<td colspan="2">
<asp:Label ID="lblDate" runat="server" Text='<%# Item.ReleaseDate %>'></asp:Label>
</td>
</tr>
<tr>
<td colspan="3">
<asp:Label ID="lblComment" runat="server" Text='<%# Item.Comment %>'>
</asp:Label>
</td>
</tr>
</table>
</ItemTemplate>
<SeparatorTemplate>
<hr />
</SeparatorTemplate>
<AlternatingItemTemplate>
<table>
<tr>
<td colspan="2">
<asp:Label ID="Label1" runat="server" Text='<%# Item.ReleaseDate %>'></asp:Label>
</td>
</tr>
<tr>
<td colspan="3">
<asp:Label ID="Label2" runat="server" Text='<%# Item.Comment %>'>
</asp:Label>
</td>
</tr>
</table>
</AlternatingItemTemplate>
</asp:Repeater>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnSubmit" />
</Triggers>
</asp:UpdatePanel>
</td>
</tr>
<tr>
<td>
<table>
<tr>
<td colspan="2">Add Your Comment</td>
</tr>
<tr>
<td colspan="2">
<asp:Label ID="lblStatus" runat="server" Visible="False"></asp:Label>
</td>
<td>&nbsp
</td>
</tr>
<tr>
<td colspan="2">
<asp:TextBox ID="txtcomment" runat="server" TextMode="MultiLine">
</asp:TextBox>
</td>
<td>&nbsp
</td>
</tr>
<tr>
<td>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" />
</td>
<td>&nbsp
</td>
</tr>
</table>
</td>
</tr>
</table>

dhtmlxScheduler for ASP.NET lightbox and server side controller

We have problem with custom lightbox in dhtmlxScheduler because in your example you used the HTML controller. can we use server side controller in our custom lightbox By the way did you place custome form in side User Controller
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="uc_taskFrom.ascx.cs" Inherits="Compudata_ProjectManager.userController.uc_taskFrom" %>
<div>
<!-- begin of Content Create TaskForm -->
<!-- Script manager-->
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<!-- Validation Summary msg vs_TaskForm-->
<asp:ValidationSummary ID="vs_TaskForm" runat="server" ForeColor="#CC0000" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<!-- begin of Content Create TaskForm -->
<asp:Panel ID="Panel1" runat="server" GroupingText="Create New Task">
<table>
<tr>
<td>
<label>
Project:</label>
</td>
<td>
<asp:DropDownList ID="ddl_projectsList" runat="server" DataSourceID="SqlDataSourceProjectList"
DataTextField="projectName" DataValueField="projectID" AppendDataBoundItems="True"
OnSelectedIndexChanged="ddl_projectsList_SelectedIndexChanged" AutoPostBack="True">
<asp:ListItem Value="-1">Select Project</asp:ListItem>
</asp:DropDownList>
<asp:CompareValidator ID="cv_projectList" runat="server" ControlToValidate="ddl_projectsList"
ErrorMessage="Select Project" ForeColor="#FC0000" Operator="NotEqual" ValueToCompare="-1">*</asp:CompareValidator>
<asp:SqlDataSource ID="SqlDataSourceProjectList" runat="server" ConnectionString="<%$ ConnectionStrings:Compudata_ProjectManagerConnection %>"
SelectCommand="SELECT [projectID], [projectName] FROM [Projects] ORDER BY [projectName]">
</asp:SqlDataSource>
</td>
</tr>
<tr>
<td>
<label>
Task Name:</label><em>*</em>
</td>
<td>
<asp:TextBox ID="txtb_taskName" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfv_taskName" runat="server" ControlToValidate="txtb_taskName"
ErrorMessage="Enter Task Name" ForeColor="#F60000">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
Default Tech:
</td>
<td>
<asp:Literal ID="lit_dafaultTech" runat="server"></asp:Literal>
</td>
</tr>
<tr>
<td>
<label>
Assigned To :</label><em>*</em>
</td>
<td>
<asp:DropDownList ID="ddl_usersList" runat="server" AppendDataBoundItems="True" DataSourceID="SqlDataSourceUserList"
DataTextField="UserName" DataValueField="UserId">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="ddl_usersList"
CssClass="Validator" ErrorMessage="select Tech" InitialValue="-1">*</asp:RequiredFieldValidator>
<asp:SqlDataSource ID="SqlDataSourceUserList" runat="server" ConnectionString="<%$ ConnectionStrings:Compudata_ProjectManagerConnection %>"
SelectCommand="SELECT [UserId], [UserName] FROM [vw_aspnet_Users]"></asp:SqlDataSource>
</td>
</tr>
<tr>
<td>
<label>
Status :</label><em>*</em>
</td>
<td>
<asp:DropDownList ID="ddl_status" runat="server" AppendDataBoundItems="True">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="ddl_status"
ErrorMessage="select Status" InitialValue="-1" CssClass="Validator">*</asp:RequiredFieldValidator>
<asp:SqlDataSource ID="status_sqlDS" runat="server" ConnectionString="<%$ ConnectionStrings:Compudata_ProjectManagerConnection %>"
SelectCommand="GetAllStatus" SelectCommandType="StoredProcedure"></asp:SqlDataSource>
</td>
</tr>
<tr>
<td>
<label>
Priorty:</label><em>*</em>
</td>
<td>
<asp:DropDownList ID="ddl_priority" runat="server" AppendDataBoundItems="True">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="ddl_priority"
ErrorMessage="Select one" CssClass="Validator" InitialValue="-1">*</asp:RequiredFieldValidator>
<asp:SqlDataSource ID="priority_sqlDC" runat="server" ConnectionString="<%$ ConnectionStrings:Compudata_ProjectManagerConnection %>"
SelectCommand="GetAllPriority" SelectCommandType="StoredProcedure"></asp:SqlDataSource>
</td>
</tr>
<tr>
<td>
<label>
Estimate Time eg(1.50):</label>
</td>
<td>
<asp:TextBox ID="txtb_estTime" runat="server" Style="direction: ltr"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<label>
Description:</label><em>*</em>
</td>
<td>
<asp:TextBox ID="txtb_Description" runat="server" TextMode="MultiLine"
Width="600px" Height="300px"></asp:TextBox>
</td>
</tr>
<tr>
<td>
</td>
</tr>
<tr>
<td colspan="2">
<label>
Send Email:
</label>
<asp:CheckBox ID="ch_sendEmail" runat="server" Text="Send Email to assigned Tech"
Checked="True" />
</td>
</tr>
<tr>
<td>
<label>Start Date: </label>
</td>
<td>
<asp:TextBox ID="txtb_startDate" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<label>End Date: </label>
</td>
<td>
<asp:TextBox ID="txtb_endDate" runat="server" CssClass=".datetimepicker"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<label>show on Calendar </label>
</td>
<td>
<asp:CheckBox ID="chb_calendar" runat="server" Text="show on Calendar"></asp:CheckBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblMessage" runat="server"></asp:Label>
</td>
<td>
<asp:Button ID="btn_createTask" runat="server" Text="Create Task" OnClick="createTask_Click" />
<asp:Button ID="Button2" runat="server" Text="Cancel" />
</td>
</tr>
</table>
<br />
<!-- begin of Web template option -->
<table class="style1">
<tr>
<td>
<asp:LinkButton ID="lnkb_clientRMA" runat="server"
onclick="lnkb_clientRMA_Click"
>CLIENT RMA RETURN</asp:LinkButton> </td>
<td>
<asp:LinkButton ID="lnkb_LG_SERVICE" runat="server"
onclick="lnkb_LG_SERVICE_Click">LG SERVICE</asp:LinkButton> </td>
<td>
<asp:LinkButton ID="lnkb_PHONE_REMOTESUPPORT" runat="server"
onclick="lnkb_PHONE_REMOTESUPPORT_Click">PHONE/REMOTE SUPPORT</asp:LinkButton> </td>
<td>
<asp:LinkButton ID="lnkb_SEAGATE_RMA_RETURN" runat="server"
onclick="lnkb_SEAGATE_RMA_RETURN_Click">SEAGATE RMA RETURN</asp:LinkButton> </td>
<td>
<asp:LinkButton ID="lnkb_ON_SITE_SERVICE" runat="server"
onclick="lnkb_ON_SITE_SERVICE_Click"> ON-SITE SERVICE</asp:LinkButton></td>
<td>
<asp:LinkButton ID="lnkb_ZEISS_RMA_DIAGNOSTIC" runat="server"
onclick="lnkb_ZEISS_RMA_DIAGNOSTIC_Click">ZEISS RMA AND DIAGNOSTIC</asp:LinkButton> </td>
</tr>
<tr>
<td>
<asp:LinkButton ID="lnkb_LENOVO_SERVICE" runat="server"
onclick="lnkb_LENOVO_SERVICE_Click">LENOVO SERVICE</asp:LinkButton></td>
<td>
<asp:LinkButton ID="lnkb_MONTHLY_SERVICE" runat="server"
onclick="lnkb_MONTHLY_SERVICE_Click">MONTHLY SERVICE</asp:LinkButton> </td>
<td>
<asp:LinkButton ID="lnkb_Power_Supply_RMA" runat="server"
onclick="lnkb_Power_Supply_RMA_Click">Power Supply RMA</asp:LinkButton></td>
<td>
<asp:LinkButton ID="lnkb_IN_SHOP_SERVICE" runat="server"
onclick="lnkb_IN_SHOP_SERVICE_Click" >IN-SHOP SERVICE</asp:LinkButton></td>
<td>
<asp:LinkButton ID="lnkb_VENDOR_RMA_RETURN" runat="server"
onclick="lnkb_VENDOR_RMA_RETURN_Click">VENDOR RMA RETURN</asp:LinkButton></td>
<td>
</td>
</tr>
</table>
<!-- end of Web template option -->
</asp:Panel>
<!-- end of Content Create TaskForm -->
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddl_projectsList" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
</div>
you can place your web form in .aspx page and use this function this line will create iframe window
Scheduler.Lightbox.SetExternalLightboxForm("formName.aspx")

Categories