FindControl returns empty textbox object / null - c#

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.

Related

.NET ListView not populating on control selection

I have a ListView in .NET that is hooked up to various CRUD methods, the select method that accepts a value doesn't seem to be working. The Data Source is supposed to be taking the value from a drop down list control, taking the selected value. when I do the configure data source method in visual studio, I select this method for my select operation:
EntReqList_byID(Int32 programID), returns List<EntranceRequirementInfo>
Then when I define parameters in the next part of the wizard, I pick control as a parameter source, with the control ID set to CertificateList, which shows the programID as the parameter from CertificateList.SelectedValue.
When I run the page, and select an item from the CertificateList, and click "Show Program", all my data is pulled except for that in the list view. My code is as follows:
The top of my page:
Please select the program credential type:
<asp:DropDownList ID="InitialCredential" runat="server" AutoPostBack="True" OnSelectedIndexChanged="InitialCredential_SelectedIndexChanged">
<asp:ListItem>[Select]</asp:ListItem>
<asp:ListItem>Certificate</asp:ListItem>
<asp:ListItem>Diploma</asp:ListItem>
<asp:ListItem>Degree</asp:ListItem>
</asp:DropDownList>
</p>
<p>
Please select a program:
<asp:DropDownList ID="CertificateList" runat="server" DataSourceID="CertificateODS" DataTextField="ProgramName" DataValueField="ProgramID" Visible="false"></asp:DropDownList>
<asp:DropDownList ID="DiplomaList" runat="server" DataSourceID="DiplomaListODS" DataTextField="ProgramName" DataValueField="ProgramID" Visible="false"></asp:DropDownList>
<asp:DropDownList ID="DegreeList" runat="server" DataSourceID="DegreeListODS" DataTextField="DegreeName" DataValueField="DegreeID" Visible="false"></asp:DropDownList>
</p>
<p>
<asp:LinkButton ID="ShowUpdateFields" runat="server" OnClick="ShowUpdateFields_Click">Show Program</asp:LinkButton>
</p>
My ListView:
<asp:ListView ID="EntReqListView" runat="server" DataSourceID="EntranceReqODS" InsertItemPosition="LastItem">
<AlternatingItemTemplate>
<tr style="">
<td>
<asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="Delete" />
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
</td>
<td>
<asp:Label ID="ProgramIDLabel" runat="server" Text='<%# Eval("ProgramID") %>' />
</td>
<td>
<asp:Label ID="CourseIDLabel" runat="server" Text='<%# Eval("CourseID") %>' />
</td>
<td>
<asp:Label ID="CourseNameLabel" runat="server" Text='<%# Eval("CourseName") %>' />
</td>
<td>
<asp:Label ID="MarkLabel" runat="server" Text='<%# Eval("Mark") %>' />
</td>
</tr>
</AlternatingItemTemplate>
<EditItemTemplate>
<tr style="">
<td>
<asp:Button ID="UpdateButton" runat="server" CommandName="Update" Text="Update" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Cancel" />
</td>
<td>
<asp:TextBox ID="ProgramIDTextBox" runat="server" Text='<%# Bind("ProgramID") %>' />
</td>
<td>
<asp:TextBox ID="CourseIDTextBox" runat="server" Text='<%# Bind("CourseID") %>' />
</td>
<td>
<asp:TextBox ID="CourseNameTextBox" runat="server" Text='<%# Bind("CourseName") %>' />
</td>
<td>
<asp:TextBox ID="MarkTextBox" runat="server" Text='<%# Bind("Mark") %>' />
</td>
</tr>
</EditItemTemplate>
<EmptyDataTemplate>
<table runat="server" style="">
<tr>
<td>No data was returned.</td>
</tr>
</table>
</EmptyDataTemplate>
<InsertItemTemplate>
<tr style="">
<td>
<asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="Insert" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Clear" />
</td>
<td>
<asp:TextBox ID="ProgramIDTextBox" runat="server" Text='<%# Bind("ProgramID") %>' />
</td>
<td>
<asp:TextBox ID="CourseIDTextBox" runat="server" Text='<%# Bind("CourseID") %>' />
</td>
<td>
<asp:TextBox ID="CourseNameTextBox" runat="server" Text='<%# Bind("CourseName") %>' />
</td>
<td>
<asp:TextBox ID="MarkTextBox" runat="server" Text='<%# Bind("Mark") %>' />
</td>
</tr>
</InsertItemTemplate>
<ItemTemplate>
<tr style="">
<td>
<asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="Delete" />
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
</td>
<td>
<asp:Label ID="ProgramIDLabel" runat="server" Text='<%# Eval("ProgramID") %>' />
</td>
<td>
<asp:Label ID="CourseIDLabel" runat="server" Text='<%# Eval("CourseID") %>' />
</td>
<td>
<asp:Label ID="CourseNameLabel" runat="server" Text='<%# Eval("CourseName") %>' />
</td>
<td>
<asp:Label ID="MarkLabel" runat="server" Text='<%# Eval("Mark") %>' />
</td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table runat="server">
<tr runat="server">
<td runat="server">
<table id="itemPlaceholderContainer" runat="server" border="0" style="">
<tr runat="server" style="">
<th runat="server"></th>
<th runat="server">ProgramID</th>
<th runat="server">CourseID</th>
<th runat="server">CourseName</th>
<th runat="server">Mark</th>
</tr>
<tr id="itemPlaceholder" runat="server">
</tr>
</table>
</td>
</tr>
<tr runat="server">
<td runat="server" style="">
<asp:DataPager ID="DataPager1" runat="server">
<Fields>
<asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" ShowLastPageButton="True" />
</Fields>
</asp:DataPager>
</td>
</tr>
</table>
</LayoutTemplate>
<SelectedItemTemplate>
<tr style="">
<td>
<asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="Delete" />
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
</td>
<td>
<asp:Label ID="ProgramIDLabel" runat="server" Text='<%# Eval("ProgramID") %>' />
</td>
<td>
<asp:Label ID="CourseIDLabel" runat="server" Text='<%# Eval("CourseID") %>' />
</td>
<td>
<asp:Label ID="CourseNameLabel" runat="server" Text='<%# Eval("CourseName") %>' />
</td>
<td>
<asp:Label ID="MarkLabel" runat="server" Text='<%# Eval("Mark") %>' />
</td>
</tr>
</SelectedItemTemplate>
</asp:ListView>
My Code behind:
protected void InitialCredential_SelectedIndexChanged(object sender, EventArgs e)
{
//display programs DDL based on credential choice
if(InitialCredential.SelectedValue == "Certificate")
{
CertificateList.Visible = true;
DiplomaList.Visible = false;
DegreeList.Visible = false;
}
else if (InitialCredential.SelectedValue == "Diploma")
{
CertificateList.Visible = false;
DiplomaList.Visible = true;
DegreeList.Visible = false;
}
else if (InitialCredential.SelectedValue == "Degree")
{
CertificateList.Visible = false;
DiplomaList.Visible = false;
DegreeList.Visible = true;
}
else
{
CertificateList.Visible = false;
DiplomaList.Visible = false;
DegreeList.Visible = false;
}
}
protected void CredentialType_SelectedIndexChanged(object sender, EventArgs e)
{
switch (CredentialType.SelectedValue)
{
case "Diploma":
{
entrance_req.Visible = true;
degree_link.Visible = false;
degree_pathways.Visible = true;
}
break;
case "Certificate":
{
entrance_req.Visible = true;
degree_link.Visible = false;
degree_pathways.Visible = false;
}
break;
case "Degree":
{
entrance_req.Visible = false;
degree_link.Visible = true;
degree_pathways.Visible = false;
}
break;
default:
{
entrance_req.Visible = false;
degree_link.Visible = false;
degree_pathways.Visible = false;
}
break;
}
}
protected void ShowUpdateFields_Click(object sender, EventArgs e)
{
show_update_form.Visible = true;
if (InitialCredential.SelectedValue == "Certificate")
{
DiplomaCertificate certificate = new DiplomaCertificate();
PathwaysController controller = new PathwaysController();
certificate = controller.CertificateProgram_byID(int.Parse(CertificateList.SelectedValue));
ProgramName.Text = certificate.ProgramName;
CategoryList.SelectedValue = certificate.CategoryID.ToString();
CredentialType.SelectedValue = "Certificate";
ProgramLength.Text = certificate.ProgramLength;
ProgramLink.Text = certificate.ProgramLink;
Activated.Checked = certificate.Activated;
WorkOutdoors.Checked = certificate.WorkOutdoors;
ShiftWork.Checked = certificate.ShiftWork;
Travel.Checked = certificate.WorkTravel;
}
}
Is there something I am missing to make it get the programID, and populate the data?

hide textbox by onselectIndexChange event

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>

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

DataList Question

I have the following databound DataList inside an UpdatePanel which updates whenever a selection is made from a DropDown menu.
However, if nothing is retrieved from the db table, I get a blank section.
What I would like to do is display the same table which is inside the ItemTemplate along with text - i.e. 'Admin Not Found', 'Email Not Found'....etc for the EmptyDataTempate...
I've noticed that the EmptyDataTemplate doesn't exist for a DataList, but I don't want to use a different control.
Is there a way to do this? Sample code appreciated. Thanks!
<asp:DataList ID="DataList" runat="server">
<ItemTemplate>
<table>
<tr>
<td class="style1">
Company Admin:
</td>
<td>
<asp:TextBox Text='<%# Eval("CompanyAdmin") %>' CssClass="input input1" ID="co_admin"
Width="150" runat="server" ReadOnly="True" />
</td>
</tr>
<tr>
<td>
Admin Email:
</td>
<td>
<asp:TextBox Text='<%# Eval("AdminEmail") %>' CssClass="input input1" ID="ad_email"
Width="150" runat="server" ReadOnly="True" />
</td>
</tr>
<tr>
<td>
Company Email:
</td>
<td>
<asp:TextBox Text='<%# Eval("CompanyEmail") %>' CssClass="input input1" ID="co_email"
Width="150" runat="server" ReadOnly="True" />
</td>
</tr>
<tr>
<td>
Telephone:
</td>
<td>
<asp:TextBox Text='<%# Eval("Telephone") %>' CssClass="input input1" ID="telephone"
Width="150" runat="server" ReadOnly="True" />
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
You can add a simple function that return a msg if the field is null.
You call a function like
<%#GetWithMsg(Container.DataItem, "CompanyEmail", "e-mail n/a")%>
for example
<asp:TextBox Text='<%# GetWithMsg(Container.DataItem, "CompanyEmail", "e-mail n/a") %>' CssClass="input input1" ID="co_email"
Width="150" runat="server" ReadOnly="True" />
and the code behind.
protected string GetWithMsg(object oItem, string cField, string TheMsg)
{
var TheData = DataBinder.Eval(oItem, cField);
if(TheData == null)
return TheMsg;
else
return TheData.ToString();
}
not tested but mybe you can try
'<%# !string.IsNullOrEmpty(Eval("CompanyEmail").ToString()) ? Eval("CompanyEmail") : "Email Not Found" %>'
explicit casting might be better in terms of performance than eval though
e.g.
'<%# !string.IsNullOrEmpty(((System.Data.DataRowView)Container.DataItem)["CompanyEmail"].ToString()) ? ((System.Data.DataRowView)Container.DataItem)["CompanyEmail"].ToString() : "Email Not Found" %>'
hope itll help
Sample Edit:
protected void BindData()
{
DataTable dt = DAL.GetData(...
if(dt.Rows.Count == 0)
{
dt.Rows.Add(dt.NewRow());
}
DataList.DataSource = dt;
DataList.DataBind();
}

Table display issue

I got a table with 2 nested tables inside that display my two repeaters. My repeaters display Home and office addresses respectively. The problem is that whenever I add a new record in one repeater, the other repeater table's display gets messed up. Like if I add a record in rpt1 , then table for rpt1 moves up and table for rpt2 goes down..ie the headers do not display in one single line . They move up and down when records are added or deleted. WHat I want is these headers to be fixed so if I add new records or delete records, the headings of both repeaters display on the same line...How do I fix this ? Hope its not confusing.
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td width="50%">
<asp:Panel ID="pnlAddAddress" runat="server">
<asp:Repeater ID="rpt1" OnItemCommand="rpt1_ItemCommand" runat="server" OnItemDataBound="rpt1_OnItemDataBound">
<HeaderTemplate>
<table width="99%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td colspan="5" class="linegrey">
</td>
</tr>
<tr class="lgrey">
<td>
Address1
</td>
<td>
City
</td>
<td>
State
</td>
<td>
IsDefault
</td>
<td>
Actions
</td>
</tr>
<tr>
<td colspan="5" class="dots">
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:LinkButton ID="lnkAddressB" runat="server" Text='<%# Eval("Address1")%>' CommandName="DisplayAddressB" CommandArgument='<%#Eval("AddID") %>' CausesValidation=false></asp:LinkButton>
</td>
<td>
<%# Eval("City")%>
</td>
<td>
<%# Eval("State")%>
</td>
<td>
<%-- Visible='<%# Eval("IsDefault")%>'--%>
<asp:LinkButton ID="lnkDefaultB" Text="Set as Default" CommandName="SetDefaultB" runat="server" CommandArgument='<%# Eval("AddID") + "," + Eval("IsB") %>'
CausesValidation="false" Visible='<%# Eval("IsDefault")%>'></asp:LinkButton>
<asp:Label ID="labelDefaultB" Text="Yes" runat="server" Visible='<%# Eval("IsDefault")%>'></asp:Label>
</td>
<td>
<asp:ImageButton ID="lnkAdd" CommandArgument='<%#Eval("AddID") %>'
CausesValidation="false" CommandName="Edit" runat="server" ImageUrl="~/images/Edit.gif" Width="14" Height="14" ToolTip="Edit"></asp:ImageButton>
<asp:ImageButton ID="lnkDel" Text="Delete" CommandArgument='<%#Eval("AddID") %>'
CausesValidation="false" CommandName="Delete" runat="server" ImageUrl="~/images/Delete.gif" Width="14" Height="14" ToolTip="Delete"></asp:ImageButton>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</asp:Panel>
</td>
<td>
<asp:Panel ID="pnlSping" runat="server">
<asp:Repeater ID="rpt12" OnItemCommand="rpt12_ItemCommand" runat="server" OnItemDataBound="rptSpping_OnItemDataBound">
<HeaderTemplate>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td colspan="5" class="linegrey">
</td>
</tr>
<tr class="lgrey">
<td>
Address1
</td>
<td>
City
</td>
<td>
State
</td>
<td>
IsDefault
</td>
<td>
Actions
</td>
</tr>
<tr>
<td colspan="5" class="dots">
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:LinkButton ID="lnkAddressS" runat="server" Text='<%# Eval("Address1")%>' CommandArgument='<%#Eval("AddID") %>' CommandName="DisplayAddressS" CausesValidation="false"></asp:LinkButton>
</td>
<td>
<%# Eval("City")%>
</td>
<td>
<%# Eval("State")%>
</td>
<td>
<asp:LinkButton ID="lnkDefaultS" Text="Set as Default" CommandName="SetDefaultS" runat="server" Visible=true CommandArgument='<%# Eval("AddID") + "," + Eval("IsS") %>'
CausesValidation="false"></asp:LinkButton>
<asp:Label ID="labelDefaultS" Text="Yes" runat="server" Visible=true></asp:Label>
</td>
<td>
<asp:ImageButton ID="lnkAdd" Text="Edit" CommandArgument='<%#Eval("AddID") %>'
CausesValidation="false" CommandName="Edit" runat="server" ImageUrl="~/images/Edit.gif" Width="14" Height="14" ToolTip="Edit"></asp:ImageButton>
<asp:ImageButton ID="lnkDel" Text="Delete" CommandArgument='<%#Eval("AddID") %>'
CausesValidation="false" CommandName="Delete" runat="server" ImageUrl="~/images/Delete.gif" Width="14" Height="14" ToolTip="Delete"></asp:ImageButton>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</asp:Panel>
</td>
</tr>
</table>
Use css attribute valign and set its value to top like this <td width="50%" valign="top">.
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td width="50%" valign="top">
<asp:Panel ID="pnlAddAddress" runat="server">
......
</asp:Panel>
</td>
<td valign="top">
<asp:Panel ID="pnlSping" runat="server">
......
</asp:Panel>
</td>
</tr>
</table>
For headers look to use the <th> element, this will keep them at the top of the table.
Put the <table> tags you do have outside your repeater controls, make sure the repeater only renders a single row and the same for the header.
Unless you have good reason consider just wrapping the two tables in <div> tags as nested tables really don't work ideally for layout.

Categories