C# What is the wrong in this reference master page code? - c#-4.0

I need to reference a master page to content pages in order to change the css style of the Home page which is referenced to the master page. This is my control which i need to change it, its located on the master page.
<table cellpadding="0" cellspacing="14" border="0" class="navigationButtons">
<tr>
<td id="HomeLink" runat="server" align="center"><br />Home</td>
<td id="AboutLink" runat="server" align="center"><br />About us</td>
<td id="ColLink" runat="server" align="center"><br />Collections</td>
<td id="RegLink" runat="server" align="center"><br />Register</td>
</tr>
</table>
I need to change the <td> style on each content page. I know that I should first reference the master page on the home page for example. But I dont know how to use the FindControl. This what I have on my server side.
HtmlGenericControl HomeLink = null;
HomeLink = (HtmlGenericControl)Master.FindControl("HomeLink");
HomeLink.Style.Add["Background-color"] = blue;
And of course its not working. Help me please.

Add runat="server" to your td tags
FindControl is not recursive. MSDN says "This method will find a control only if the control is directly contained by the specified container; that is, the method does not search throughout a hierarchy of controls within controls"
http://msdn.microsoft.com/en-us/library/486wc64h.aspx
public static Control FindControl(Control control, string id)
{
if (control.Id == id)
return control;
foreach(Control c in control.Controls)
{
Control res = FindControl(c, id);
if (res != null)
return res;
}
return null;
}

Related

How to make a Sharepoint drop-down list in read only

I'm new with Sharepoint. I have a form and I edit it with Sharepoint designer.
I would like to disable a drop-down list (I want just show the value without the possibility to change it). I don't know exactly how to do that directly in the code of the Sharepoint field?
Here my field:
<tr class="UniqueKeyMasterContract">
<td width="190px" valign="top" class="ms-formlabel">
<H3 class="ms-standardheader">
<nobr>UniqueKey</nobr>
</H3>
</td>
<td width="400px" valign="top" class="ms-formbody">
<SharePoint:FormField runat="server" id="ff1{$Pos}" ControlMode="New" FieldName="UniqueKeyMasterContract" __designer:bind="{ddwrt:DataBind('i',concat('ff1',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(#ID)),'#UniqueKeyMasterContract')}"/>
<SharePoint:FieldDescription runat="server" id="ff1description{$Pos}" FieldName="UniqueKeyMasterContract" ControlMode="New"/>
</td>
</tr>
Could you please help me with that ?
You could add a script editor in the form page, and add the following code to the script editor web part.
<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
<script>
$(function () {
$('select[title="Choice"]').change(
function(){
this.selectedIndex=this.defaultIndex;
}
)
})
</script>
Tip: Pay attention to modify the jQuery selector.

How can i find an element by xpath text() and the second cousin of this element?

I use Htmlunit in java. I need to find an element by text(), and i need the second cousin of this element (i think).
I tried this:
HtmlElement element = page.getFirstByXPath("//*[text() = \"SOMETHING\"]/parent/following-sibling/child");
System.out.println(element.asText()); // it's null
Update:
The html source page:
<tr>
<script>
_l('its not important')
</script>
<td valign="top">
<font class="its not important">
</td>
<td valign="top">
<font class="its not important">
SOMETHING
<script>
_l('its not important')
</script>
</font>
<script>
_l('its not important')
</script>
</td>
</tr>
<tr>
<td></td>
<td valign="top">
THE INFORMATION I NEED
</td>
</tr>
The following XPath should work:
//tr[td/*[contains(text(), "SOMETHING")]]/following-sibling::tr/td[#valign ="top"]
It will select a <tr> element, which does have a grandchild with the required text. Then it will select all following siblings and select the next element. Please note that I selected the correct <td> element basec on the valign attribute value, you might not want to do that and instead use the position, i.e. td[2]
try
//*[text() = \"SOMETHING\"]/../following-sibling::*[1]/*[1]

Button Event Code Behind not Firing on Azure

I have a fairly simple single page web application that I have fully tested locally. This application is a simple form submission, with the data being stored in a Azure Table Storage container.I have one code-behind function for the Submit button where I am doing server side validation with messages displaying in a pop-up window.
Everything works fine on my local machine, including all data storage and retrieval back to Azure. As soon as I publish the site to Azure, the code-behind will not fire and I am not getting any errors within the site itself. Any ideas?
Brian
Please see all the code below:
<form id="form1" runat="server">
<telerik:RadWindowManager ID="DefaultWindowMgr" runat="server"></telerik:RadWindowManager>
<telerik:RadScriptManager ID="RadScriptManager1" runat="server"></telerik:RadScriptManager>
<div id="main" style="width:1024px; height:650px; margin-left:auto; margin-right:auto; background-image:url(../Images/earthBG.png);">
<div id="left" style="width:500px;float:left;left:5px;margin-left:auto;margin-right:auto;">
<asp:Image ID="Image1" runat="server" ImageAlign="Middle" ImageUrl="~/Images/TRACLogo.png" />
<asp:Image ID="Image2" runat="server" ImageUrl="~/Images/dashboardGlobe.png" ImageAlign="Middle" />
</div>
<div id="right" style="width:500px;float:right;top:75px;position:relative;">
<p>Some kind of Welcome Text needs to go here.</p>
<table id="RiskFormTable" style="width:100%;padding:5px;">
<tr>
<td style="text-align:right"><asp:Label ID="LblCompany" runat="server" Text="Company Name:"></asp:Label></td>
<td style="text-align:left"><telerik:RadTextBox ID="TxtCompany" runat="server" Width="220px"></telerik:RadTextBox></td>
</tr>
<tr>
<td style="text-align:right"><asp:Label ID="LblEmail" runat="server" Text="Email Address of POC:"></asp:Label></td>
<td style="text-align:left"><telerik:RadTextBox ID="TxtEmail" runat="server" Width="220px"></telerik:RadTextBox></td>
</tr>
<tr>
<td style="text-align:right"><asp:Label ID="LblCountries" runat="server" Text="What countries do you do business in?"></asp:Label></td>
<td style="text-align:left">
<telerik:RadListBox ID="LstCountries" runat="server" DataSortField="name" DataSourceID="XMLCountriesSource" DataTextField="name" DataValueField="score" Height="118px" SelectionMode="Multiple" Sort="Ascending" Width="220px" CausesValidation="False"></telerik:RadListBox>
</td>
</tr>
<tr>
<td style="text-align:right"><asp:Label ID="LblPrimary" runat="server" Text="What is your primary customer segment?"></asp:Label></td>
<td style="text-align:left">
<telerik:RadComboBox ID="DDLPrimary" runat="server" Width="220px" DataSourceID="XMLSegmentsSource" DataTextField="name" DataValueField="value" CausesValidation="False"></telerik:RadComboBox>
</td>
</tr>
<tr>
<td style="text-align:right"><asp:Label ID="LblSecondary" runat="server" Text="What is your secondary customer segment?"></asp:Label></td>
<td style="text-align:left">
<telerik:RadComboBox ID="DDLSecondary" runat="server" Width="220px" DataSourceID="XMLSegmentsSource" DataTextField="name" DataValueField="value" CausesValidation="False"></telerik:RadComboBox>
</td>
</tr>
<tr>
<td style="text-align:right" colspan="2">
<telerik:RadButton ID="BtnSubmit" runat="server" Text="Submit" SingleClick="true" OnClick="BtnSubmit_Click" CausesValidation="False"></telerik:RadButton>
</td>
</tr>
</table>
</div>
</div>
</form>
Here is the code behind:
using System;
using System.Configuration;
using TRACERiskLibrary.Entities;
using TRACERiskLibrary.Managers;
namespace TRACERisk
{
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
/// <summary>
/// This function will get fired when a user submits the Risk Assessment data. It will verify that all of the
/// data is accurate and then will save the entry to the Azure Table that is found within the web.config file.
/// If any of the data is inaccurate or there is a problem with the saving of the data, the error will be
/// displayed to the user within the RadWindowManager Alert window.
/// </summary>
protected void BtnSubmit_Click(object sender, EventArgs e)
{
String azureconn = ConfigurationManager.ConnectionStrings["traceRiskAzure"].ConnectionString;
String azuretable = ConfigurationManager.AppSettings["AzureTable"];
if (TxtEmail.Text.CompareTo("") == 0 || TxtEmail.Text.IndexOf('#') < 0 || TxtEmail.Text.IndexOf('.') < 0)
{
DefaultWindowMgr.RadAlert("You must enter in a valid Email Address for this submission to be valid. Please try again.", 400, 250, "Risk Survey Submission Error", "");
return;
}
DellRiskEntity entity = new DellRiskEntity(TxtEmail.Text);
if (TxtCompany.Text.CompareTo("") == 0)
{
DefaultWindowMgr.RadAlert("You must enter in a Company Name for this submission to be valid. Please try again.", 400, 250, "Risk Survey Submission Error", "");
return;
}
else
entity.Company = TxtCompany.Text;
entity.PrimaryBus = DDLPrimary.SelectedItem.Text;
entity.PrimaryScore = (Int32) Decimal.Parse(DDLPrimary.SelectedValue);
entity.SecondaryBus = DDLSecondary.SelectedItem.Text;
entity.SecondaryScore = (Int32) Decimal.Parse(DDLSecondary.SelectedValue);
// Verify that the user entered in at least one country of business, if not throw up an error message and stop processing.
Int32 countryscore = 0;
if (LstCountries.SelectedItems.Count == 0)
{
DefaultWindowMgr.RadAlert("Please select one or more Countries for which you do business before submitting.", 400, 250, "Risk Survey Submission Error", "");
return;
}
else
{
for (int i = 0; i < LstCountries.SelectedItems.Count; i++)
{
entity.Countries.Add(LstCountries.SelectedItems[i].Text);
if (Int32.Parse(LstCountries.SelectedItems[i].Value) > countryscore)
countryscore = Int32.Parse(LstCountries.SelectedItems[i].Value);
}
}
entity.CountryScore = countryscore;
entity.TotalScore = entity.PrimaryScore + entity.SecondaryScore + entity.CountryScore;
if (entity.TotalScore < 11)
entity.TierLevel = "Tier 1";
else if (entity.TotalScore < 21)
entity.TierLevel = "Tier 2";
else
entity.TierLevel = "Tier 3";
// Process the actual saving of the Risk Assessment within the Azure Table
if (RiskManager.SaveEntry(entity, azureconn, azuretable))
DefaultWindowMgr.RadAlert("Your Risk Assessment has been Successfully submitted.", 400, 250, "Risk Survey Submitted", "");
else
DefaultWindowMgr.RadAlert("There is a record within the Risk Assessment associated with this email address. Please enter new Risk Assessment Data.", 400, 250, "Risk Survey Submission Error", "");
}
}
}

pagination content

I am trying to do pagination for my forum. I am trying to get the results to show from the db, although everything is everywhere.
here is my code:
<!-- start with the table -->
<table width="100%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td width="53%" align="center" bgcolor="#E6E6E6" style="padding:5px;"><strong>Topic / Thread Starter</strong></td>
<td width="15%" align="center" bgcolor="#E6E6E6" style="padding:5px;"><strong>Replies/Views</strong></td>
<td width="13%" align="center" bgcolor="#E6E6E6" style="padding:5px;"><strong>Last Post By</strong></td>
</tr>
<div id="p1" class="pagedemo _current" style="">
<?php
$sql="SELECT * FROM forum ORDER BY datetime DESC";
$result=mysql_query($sql);
$i = 1;
$z = 1;
while($rows = mysql_fetch_array($result)){ // Start looping table row
if(($i % 4) != 0)
{ ?>
<tr>
<td bgcolor="#FFFFFF" style="padding:5px;"><a class="normal" href="view_topic.php?id=<? echo $rows['id']; ?>"><? echo $rows['topic']; ?></a><br /><span style="color:#666; font-size:12px;">Started By <?php echo "<a class='normal' href='http://www.example.com/view_profile.php?user=".getID($rows[username])."'>"; ?> <? echo $rows['username']; ?></a></span></td>
<td align="center" bgcolor="#FFFFFF">Replies: <? echo $rows['reply']; ?><br />Views: <? echo $rows['view']; ?></td>
<td align="center" background="http://example.com/images/forum_fade_bckg.png"><span style="color:#666; font-size:12px;">
<?php echo "<a class='normal' href='http://www.example.com/view_profile.php?user=".getID($rows[lastPoster])."'>"; ?> <?php echo $rows['lastPoster']; ?></a><br /><?php $date = substr($rows['datetime'],0,12);
if($date == date("M d, Y")) {
echo "Today, " . substr($rows['datetime'],-8);
} else {
echo $rows['datetime'];
}?> </span></td>
</tr>
<?php
// do whatever for the page... (this is inside the div)
$message = $row['message'];
echo $i . " " . $message. "<br>";
$i+=1;
}
else
{
$z+=1;
// GET ONLY NUMBERS HERE THAT ARE DIVISIBLE BY 4!!!!
// this is the end of the starting page, and the begining of the next page
echo '<br>---end---</div>
<div id="p'.$z.'" class="pagedemo" style="display:none;">---start---<br>NEXT PAGE!!!!!!!'; //
}
}
?>
</div>
The results, instead of staying in the div, are actually below the div. when I take out everything b/w the <tr> and </tr>, it all fits into the div. What am I doing wrong?
If you view the source of the page the issue should be apparent. I see a few mistakes that could be the problem.
The TABLE at the top of the snippet ends the TR tag then a DIV starts. A DIV should only reside within a TD, TH or outside the TABLE. Also in the snippet you provided there is no ending table tag. With all the other issues that is probably the one that is messing the browser up.
Please adjust structure to be similar to this:
<div>...</div>
<table>
<tr>
<td>Some tags in here(A, DIV, SPAN, etc.)</td>
</tr>
<tr>
<td>...</td>
<td>...</td>
</tr>
</table>
<div>...</div>
Also it would be worthwhile to migrate certain attributes to css properties in the style tag. For example the background, bgcolor, align, and width attributes in your snippet.
Sorry if that does not fix the issue its hard to debug without being able to see the issue.

People search in SharePoint using partial names

My employer is switching their internal portal over to SharePoint. One of the highly used features of the previous portal was a 'people search' that allowed partial names. SharePoint 2007 defaults to keyword searches which only match against the exact word(s) given as search terms. It can do full-text searches but you have to provide the property name, e.g. "FirstName:tom" (without the quotes of course). That works for a programmatic solution but not for end users.
Is there a way in SharePoint 2007 to let users search for people using partial names?
I found this solution that works well enough for us.
Add a ContentEditor web part to the target page and go to the HTML editor button. Add the following HTML code. It creates two input fields (firstname/lastname) and then creates a query with the search terms included as property searches which will invoke the full-text search.
Note: you need to replace the search result page with the appropriate location for your configuration.
<script language="javascript">
//function to handle enter on keyboard
function txtWildPeopleFinder_KeyDown(e)
{
if (e.keyCode == 13 || e.keyCode==10)
{
e.returnValue=false;
DoWildPeopleSearch();
return false;
}
else
return true;
}
//escape apostrophes in search strings
function escapestr(str)
{
return str.replace("'","%22");
}
//search function
function DoWildPeopleSearch()
{
var firstname = escapestr(document.all["firstname"].value);
var lastname = escapestr(document.all["lastname"].value);
var url;
//search on last name
if(firstname == "")
{
url = "/searchcenter/Pages/peopleresults.aspx?k=LastName%3A" + lastname;
window.location=url;
return;
}
//search on first name
if(lastname == "")
{
url = "/searchcenter/Pages/peopleresults.aspx?k=FirstName%3A" + firstname;
window.location=url;
return;
}
//first and last
url = "/searchcenter/Pages/peopleresults.aspx?k=lastname%3A" + lastname + "%20FirstName%3A" + firstname;
window.location=url;
return;
}
</script>
<table cellpadding="2" cellspacing="0" border="0" width="100%" ID="Table3">
<tr>
<td width="80" nowrap>
First Name:
</td>
<td width="100%">
<input size="20" maxlength="100" id="firstname" name="firstname" type="text" onkeydown="txtWildPeopleFinder_KeyDown(event)">
</td>
</tr>
<tr>
<td width="80" nowrap>
Last Name:
</td>
<td>
<input size="20" maxlength="100" id="lastname" name="lastname" type="text" onkeydown="txtWildPeopleFinder_KeyDown(event)">
</td>
</tr>
<tr>
<td> </td>
<td>
<input type="button" onclick="DoWildPeopleSearch()" value="Search">
</td>
</tr>
</table>

Resources