I want to retrieve items from the database and display its on row inside the row three columns inside every column one card, the card have on item.
this is my masterpage:
<div class="products bg-dark">
<div class="container pt-3 pb-3">
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
</div>
and here is my index.aspx:
<%# Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Index.aspx.cs" Inherits="Index" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<div class="row" >
<div id="s" class='col-md-4 pt-3' runat="server">
</div>
</div>
</asp:Content>
and here is my index.aspx.cs:
con.Open();
SqlCommand cm = new SqlCommand("select ID , title , sub_title , image from Articles", con);
SqlDataReader dr = cm.ExecuteReader();
while (dr.Read())
{
s.InnerHtml +=
"<div class='card'><img class='card-img-top' src=images/" + dr["image"] + " alt='Card image cap'>" +
"<div class='card-body'>" +
"<h5 class='card-title'>" + dr["title"] + "</h5>" +
"<p class='card-text'>" + dr["sub_title"] + "</p><a href = 'Article.aspx?x=" + dr["ID"] + "class='btn btn-primary'>Read more</a></div>" +
" </div>" +
"</div>"
The problem is when I run the code. The cards don't display beside each other. its display under each other,
and when inspect I found only the first item inside the content place holders, the second item not inside.
You have to put the class of the columns (class='col-md-4 pt-3') to each card.
Therefore, pass the class to the div inside the dynamic html.
try removing class='col-md-4' from div with id="s" (in index.aspx page) and place this class for div of each card (in index.aspx.cs page)
Try to add style="display: block;" to the outer div (with the id="s").
and style="display:inline-block;" to each of the cards.
Related
I have been struggling with accessing a control in master page from a web method (or any static method for that matter).
I have a bootstrap-styled drop down in master page that list user's favorites. Items in this drop down are populated using a repeater that reads list of favorites for current user from DB and populates the drop down.
On the main page that uses this master page there are a number of reports with an "Add to favorites" button. To do this client side, I added an onclick event to button, it calls a javascript function that calls a web method to store this info (User ID, URL) in database. This part is fine. The problem is that then I need to update the dropdown (rebind the repeater).
Here is what I have and what I have tried:
In master page:
<%# Master Language="C#" AutoEventWireup="true" CodeBehind="Site.Master.cs" Inherits="EA.SiteMaster" %>
....
<asp:ScriptManager runat="server" ID="ScriptManager1" EnablePageMethods="true" />
....
<ul class="dropdown-menu" role="menu">
<asp:Repeater runat="server" ID="rptFavorites" OnItemDataBound="rptFavorites_ItemDataBound">
<ItemTemplate>
<li>
<asp:LinkButton runat="server" ID="lbFavLink" /><span class="glyphicon glyphicon-heart"></span>
</li>
</ItemTemplate>
</asp:Repeater>
</ul>
in Default.aspx:
<%# Page Title="Home Page" Language="C#" MasterPageFile="Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="EA._Default" %>
<%# MasterType virtualpath="Site.master" %>
....
function addFavorite(sURL, sFriendlyName) {
// I added this to get the routing working properly
var path = PageMethods.get_path() + '.aspx';
PageMethods.set_path(path);
PageMethods.AddUserFavorite(sURL, sFriendlyName, onSucceeded, onFailed);
}
function onSucceeded(result, userContext, methodName) {
alert(result);
}
function onFailed(result, userContext, methodName) {
alert(result);
}
....
<button type="button" class="btn btn-primary btn-xs" id="btnMPP" onclick="addFavorite('http://blahblah.com/IV/SomeReport.html','Some Report')" ><i class="fa fa-heart-o" aria-hidden="true"></i></button>
in Default.aspx.cs:
[System.Web.Services.WebMethod]
public static string AddUserFavorite(string sURL, string sFriendlyName)
{
string sMsg = string.Empty;
string sUserID = HttpContext.Current.Session["UserID"].ToString();
Favorites oFavorite = new Favorites();
oFavorite.FavoritesURL = sURL;
oFavorite.FavoritesFriendlyName = sFriendlyName;
oFavorite.UserID = sUserID;
int iRet = Favorites.AddFavrites(oFavorite);
if (-1 == iRet)
sMsg = "Failed to add to favorites list";
else
{
sMsg = "\"" + sFriendlyName + "\" (" + sURL + ") was added to your favorites list";
UpdateMaster();
}
return sMsg;
}
private static void UpdateMaster()
{
Page page = (Page)HttpContext.Current.Handler;
MasterPage mp = page.Master; <--- Always null
Repeater rptFavorites = mp.FindControl("rptFavorites") as Repeater;
if (rptFavorites != null)
{
// rebind repeater here
}
}
Any ideas on how I can achieve this is greatly appreciated. Of course, I can change the "Add to Favorites" to an ASP LinkButton and no issues, but just need to know how this approach can be done; if it can.
I don't think you need this code to access your repeater.
Page page = (Page)HttpContext.Current.Handler;
MasterPage mp = page.Master; <--- Always null
You just need to tell it to look for it in the MasterPage.
Try it this way.
(Repeater) rpt = (Repeater) Master.FindControl("rptFavorites");
I'm very new to Umbraco, I am still picking my way through how it works so it is entirely possible that I have missed something extremely obvious.
I have been asked to amend how a slider on a MasterPage functions, I've found the markup for the slider is in the .cs file for the MasterPage.
void CreateSlider()
{
if (!String.IsNullOrEmpty(CurrentContent.Slider1Image))
{
slider.InnerHtml += "<li class='foobar'>";
if (!String.IsNullOrEmpty(CurrentContent.Slider1Title))
{
slider.InnerHtml += "<img src='" + GetMedia(CurrentContent.Slider1Image) + "' alt='' />";
slider.InnerHtml += "<div class='slider_content bx-pager-item'>";
slider.InnerHtml += "<h1>" + CurrentContent.Slider1Title + "</h1>";
if (!String.IsNullOrEmpty(CurrentContent.Slider1VideoButtonTitle) && !String.IsNullOrEmpty(CurrentContent.Slider1VideoLink))
slider.InnerHtml += "<span>" + CurrentContent.Slider1VideoButtonTitle + "</span>";
slider.InnerHtml += "</div>";
if (!String.IsNullOrEmpty(CurrentContent.Slider1VideoButtonTitle) && !String.IsNullOrEmpty(CurrentContent.Slider1VideoLink))
{
slider.InnerHtml += "<div class='video_wrapper'>";
slider.InnerHtml += "<div class='youtube_container'>";
slider.InnerHtml += "<div><iframe src='https://player.vimeo.com/video/" + CurrentContent.Slider1VideoLink + "' width='100%' height='542' frameborder='0' webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe></div>";
slider.InnerHtml += "</div>";
slider.InnerHtml += "</div>";
}
}
slider.InnerHtml += "</li>";
}
}
I have tried adding a class to the <li> but it doesn't not show up in the HTML markup at all. I have tried building the project but with no joy.
Here is the markup that is output:
<%# Master Language="C#" MasterPageFile="~/masterpages/Base.master" AutoEventWireup="true" Inherits="HomePageType1" Codebehind="HomePageType1.master.cs" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
<div class="slider_container">
<ul id="ContentPlaceHolderDefault_ContentPlaceHolder1_slider" class="bxslider">
<li>
<img src='/media/img001.jpg' alt='' />
<div class='slider_content'>
<!-- SLIDE CONTENT -->
</div>
<div class='video_wrapper'>
<div class='youtube_container'>
<div>
<!-- VIDEO URL -->
</div>
</div>
</div>
</li>
</ul>
</div>
</asp:Content>
Any suggestions?
Any code added to a .cs file outside of /App_Code/ must be compiled before it "counts" - that part should be dealt with when you build the project.
Also, the master page must reference its code behind for it to pick it up, like
<%# Master Language="C#"
AutoEventWireup="true" CodeBehind="MyMasterpage.master.cs" Inherits="MyNamespace.MyMasterpage" %>
Can you perhaps also share the master page content?
The reason this was not functioning correctly is because the previous developers had compiled their code but had also uploaded the C# files to the server. So the files we received were compiled.
After much political wrangling we got them to send us the uncompiled files which allowed me to make the code changes as expected.
I have the following code:
<div id="tableWrapper">
<div id="tableScroll">
<table runat="server" id="surveyTable">
<tr>
<th>URL</th>
<th>Used</th>
</tr>
</table>
</div>
</div>
<div id="tableFooter">
<div>
Export
</div>
<div>
<input type="button" runat="server" id="btnUpdate" onserverclick="btnUpdate_ServerClick" value="Update" />
</div>
</div>
I add rows to this table in C# (a URL and a checkbox per row), after the page has rendered, users click on the checkboxes and when done, will click on the 'Update' button. Then we go to some code which should look through each row and get some data from each URL if the checkbox has been clicked.
The problem is that when I click the button there is only 1 row, the row on the HTML page. This is an issue with postback and I have tried to fight this with an UpdatePanel but no success so far. I added
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="false">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
</ContentTemplate>
<triggers>
<asp:asyncpostbacktrigger controlid="btnUpdate" EventName="ServerClick" />
</triggers>
</asp:UpdatePanel>
To the beginning and end but no joy. AJAX does work on the page as I tested this with this:
ScriptManager sm = ScriptManager.GetCurrent(Page)
if (sm == null)
{
// ASP.NET AJAX functionality is not enabled for the page.
}
else
{
// AJAX functionality is enabled for the page.
}
Can anyone advise why this isnt working?
Code to add HTML rows
foreach (var s in surveys)
{
HtmlTableRow row = new HtmlTableRow();
surveyTable.Rows.Add(row);
HtmlTableCell urlCell = new HtmlTableCell();
urlCell.InnerHtml = "url/Survey/" + s.stuff_id + "/" + s.stuff2_id + "/" + s.stuff3_id + "/";
HtmlTableCell checkBoxCell = new HtmlTableCell();
checkBoxCell.InnerHtml = "<input type=\"checkbox\" name=\"used\" " + (s.used == "Y" ? "checked" : "") + " >";
row.Cells.Add(urlCell);
row.Cells.Add(checkBoxCell);
}
the code using to show image .
HTML:
<asp:Repeater ID="Rep_slider" runat="server">
<ItemTemplate>
<div data-src='<%#("~/PicUpload/") + Eval("pic")%> ' runat="server">
<div class="camera_caption moveFromLeft camera_text_center">
<div class="caption_slider h2">
</div>
</div>
</div>
</ItemTemplate>
</asp:Repeater>
The code using to select from DB:
var slideshow = from anything in obj.sliders
select anything;
Rep_slider.DataSource = slideshow.ToArray();
Rep_slider.DataBind();
I think you want display div with background image. Try use style="background-image:url('<%#("~/PicUpload/") + Eval("pic")%>')" instead data-src
What I am trying to accomplish is to create a cookie so that after you click a save button, leave the page and then come back to the page, the value of the cookie should be displayed in a label at the top of the page welcoming the user back to the page.
Here is the code I am using.
<%# page language="C#" %>
<%# Import Namespace="System.Data" %>
<%# Import Namespace="System.Data.OleDb" %>
<script language="C#" runat="server">
String welcomeBackName;
void Page_Load(Object sender, System.EventArgs e)
{
if (Page.IsPostBack==true)
{
HttpCookie RUcookie = new HttpCookie("RUcookie");
lblMessage.Text = txtfirstname.Text.Substring(0,1).ToLower() + txtlastname.Text.ToLower() + "#radford.edu";
RUcookie.Value = "Welcome " +txtfirstname.Text +" "+ txtlastname.Text;
RUcookie.Expires = DateTime.Now.AddHours(1);
Response.Cookies.Add(RUcookie);
if(RUcookie != null)
{
welcomeBackName = Request.Cookies["RUcookie"].Value;
welcomeBack.Text = welcomeBackName;
}
}
}
</script>
<html>
<form id=form1 runat="server">
<br>
<ASP:Label id="welcomeBack" Text="" size="60" runat="server"/>
<br>
<br>
<br>
First Name: <asp:TextBox id="txtfirstname" size="20" runat="server"/><br>
<br>
Last Name : <asp:TextBox id="txtlastname" size="20" runat="server"/><br>
<br>
<ASP:Button id="butSave" Text="Save" Autopostback=true runat="server"/>
<br>
<br>
Email: <asp:Label id="lblMessage" size="80" forecolor=Blue runat="server"/><br>
</form>
</html>
Few things wrong.
You said you want this to happen when the user leaves the page and comes back. By definition, you won't be in a postback. That'd be a fresh load of the page. Instead of checking if it's a postback, you should simply check to see if the cookie exists.
The other thing is that IsPostBack is by definition, a boolean. You don't need to check if it's equivalent to true. It's either true or false.