Asp.net c#
I am using the below code..
<%String h = "hello";%>
<!-- "wall_com_insert.aspx?Tid=" + Application.Get("Tid");-->
<div id="content_sr_comment" style="height: auto"> <asp:Label ID="Label8"
runat="server" Text="<%=h%>" ></asp:Label>
</div>
But I am getting the output..
output displayed on the label: "<%=h%>"
I guess the syntax is not correct.. can I get help
You can't place a server command inside a server tag. Try this:
<div id="content_sr_comment" style="height: auto"> <%= h %></div>
Or
<script runat="server" language="C#">
void Page_Load(object sender, EventArgs e)
{
String h = "hello";
Label8.Text = h;
}
</script>
<div id="content_sr_comment" style="height: auto">
<asp:Label ID="Label8" runat="server"></asp:Label>
</div>
This should work:
<script runat="server" language="C#">
private string h = "hello";
</script>
<!-- "wall_com_insert.aspx?Tid=" + Application.Get("Tid");-->
<div id="content_sr_comment" style="height: auto"> <asp:Label ID="Label8"
runat="server"><%=h%></asp:Label>
</div>
Another approach that I find useful, especially if you want to write out a value in multiple places in your html is to create a function in your code behind like this:
protected string SayHello()
{
return "Hello";
}
You can then use it all over your html:
<div id="content_sr_comment" style="height: auto">
<%=SayHello() %>
</div>
Related
I am trying to change the css style of the repeater to a different color on different status. The expected output is to print 6 different statuses like: In progress, complete, withdrawn so on.. Currently it has a single color, so it shows one color only. the challenging part here is to change the color dynamically based on the status. how do I achieve this? Currently it pulls the style based on "status noAction text-center" class below. Should I make any changes in the code behind or is it just a front end css change. Can someone provide me an example please.
.aspx code:
<div class="row">
<asp:Repeater ID="rptStatuses" runat="server">
<ItemTemplate>
<div class="col-md-4 col-sm-4">
<div class="status noAction text-center">
<div class="banner">
<asp:Label runat="server"> <%# Eval("ID") %></asp:Label>
</div>
<div class="label"><%# Eval("Name") %></div>
</div>
</div>
</ItemTemplate>
</asp:Repeater>
.cs code relevant part
private void GB()
{
var surveyId = 55;
var stateLabels = _manageDatasets.GetStateLabels(surveyId);
List<Status> statusesList = new List<Status>();
foreach (var sl in stateLabels)
{
if (sl.Key != -1)
statusesList.Add(new Status { ID = sl.Key.ToString(), Name = sl.Value }
);
}
this.rptStatuses.DataSource = statusesList;
this.rptStatuses.DataBind();
}
I think what you want to do is change the class in the your html and just use the embedded code to be able to dynamically change the banner color, etc. based on the status. The embedded code that you want would look something like this -
<div class="col-md-4 col-sm-4">
<% if(status == "noAction") { %>
<div class="status noAction text-center">
<div class="banner">
<asp:Label runat="server"> <%# Eval("ID") %></asp:Label>
</div>
<div class="label"><%# Eval("Name") %></div>
</div>
<% } %>
If you have any column in you table from where repeater is getting datasource then that would be pretty easy to do
something like that
<asp:Repeater ID="rptStatuses" runat="server">
<ItemTemplate>
<div class="col-md-4 col-sm-4">
<div class='<%# Convert.toInt32(eval("ActionColumnName"))==1 ? "status In progress text-center" : Convert.toInt32(eval("ActionColumnName"))==2 ? "status complete text-center" : Convert.toInt32(eval("ActionColumnName"))==3 ? "status withdrawn text-center" : "status noAction text-center" '>
<div class="banner">
<asp:Label runat="server"> <%# Eval("ID") %></asp:Label>
</div>
<div class="label"><%# Eval("Name") %></div>
</div>
</div>
</ItemTemplate>
</asp:Repeater>
I have a Products page which displays a list of products. When i click Details button, i want to show product details in a bootstrap modal popup.
I want to get one of the product detail but this code gets all products details.
how can i fix this query:
.aspx code:
<asp:Repeater ID="rpProducts" runat="server">
<ItemTemplate>
<td> <div class="btn-ud" ><a href="<%#Eval("ProductID") %>" data-toggle="modal" data-target="#myModal2" class="btn btn-custom-3 btn-sm"/ >Details</a> </div> </td>
</ItemTemplate>
</asp:Repeater>
modal popup code:
<div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-hidden="true">
<asp:Repeater ID="rpProductDetails" runat="server">
<ItemTemplate>
<tbody>
<td height="100px"> <%#Eval("ProductDetails")%> </td>
<td height="100px"> <%#Eval("ProductDetails")%> </td>
</tbody>
</ItemTemplate>
</asp:Repeater>
</div>
c# code:
DataTable dtProductsDetails = system.GetDataTable("Select ProductDetails,TechDetails,Standards, ApplicationArea from TBLPRODUCTS where ProductID = ProductID");
if (dtProductsDetails.Rows.Count > 0)
{
rpProductDetails.DataSource = dtProductsDetails;
rpProductDetails.DataBind();
}
<script type="text/javascript">
function openModal() {
$('#myModal').modal('show');
}
</script>
In your c# code add an event for linkbutton like
protected void lbEdit_Click(object sender, EventArgs e) {
ScriptManager.RegisterStartupScript(this,this.GetType(),"Pop","openModal();", true);
}
You have to use jQuery for this:
$("a").click(function(){
$("#myModal2").modal("show");
});
I'm working on a project and ran into a problem.
For some reason, I can't assign data source to the repeater. I'm using usercontrol
SlideshowDemo.ascx
<asp:Repeater ID="Slideshow" runat="server">
<HeaderTemplate>
<div style="margin:0 auto; width:960px;">
<div class="slideshowInsideContainer">
<div class="slideShowText">
<div style="padding:10px;" class="SlideShowContent">
<%= firstText %>
</div>
</div>
<img id="SlideShowImage" style="position:absolute; z-index:1; top:0;" src="<%= firstImage %>" />
<img id="SlideShowImageBG" style="position:absolute; z-index:0; top:0;" src="<%= firstImage %>" />
<img id="previousBttn" style="position:absolute; z-index:2; top:200px; cursor:pointer; left:0;" src="/images/SlideShow/leftButton.png" />
<img id="nextBttn" style="position:absolute; z-index:2; top:200px; cursor:pointer; right:0;" src="/images/SlideShow/rightButton.png" />
<div class="slideshowItems">
<ul>
</HeaderTemplate>
<ItemTemplate>
<li class='<%# Container.ItemIndex == 0 ? "selected" : "" %>' id="<%# Container.ItemIndex %>">
<div class="slideshowtext">
<%# Eval("text") %>
</div>
<img style="position:absolute; z-index:1; top:0;" src=' <%# Eval("image") %>' />
</li>
</ItemTemplate>
<FooterTemplate>
</ul>
</div>
</div>
</div>
</FooterTemplate>
</asp:Repeater>
SlideshowDemo.ascx.cs
public void GetSlideshowData()
{
int ID = Convert.ToInt32(slideShowID);
Node parent = new Node(ID);
ArrayList repeaterData = new ArrayList();
Nodes children = parent.Children;
for (int i = 0; i < children.Count; i++)
{
string image = children[i].GetProperty("image").Value.ToString();
string text = children[i].GetProperty("slideshowText").Value.ToString();
if (i == 0)
{
firstImage = image;
firstText = text;
}
repeaterData.Add(new SlideShowItem(image, text));
}
Slideshow.DataSource = repeaterData; //Error: Can't recognize 'Slideshow'
Slideshow.DataBind();
}
The problem is that the SlideshowDemo.ascx.cs doesn't recognize Slideshow
I get error
The name 'Slideshow' does not exist in the current context
I also get Warning
Source file
'obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs'
specified multiple times
I would appreciate any help
I need to show asp.net progress bar for three operations on webpage. First,when file upload the progress bar should show 33 % and message 'file upload started'. Once uploaded it should show message 'validating file data' and progress 66%. At third round, it should show 'automatching data' with 99%.
I have three methods that will be called one by one. I googled a lot but couldn't find a solution for this type of problem. Can someone please help?
If you want to show progress bar you need to introduce some java script or jquery code. I am sharing a sample code you can take idea from here
<form id="form1" runat="server">
<div style="text-align: left">
<asp:FileUpload ID="FileUpload1" runat="server" /> <br />
<br />
<asp:Button ID="Button1" runat="server" Text="Upload" OnClientClick="return ProgressBar()" OnClick="Button1_Click" /><br />
<br />
<div id="divUpload" style="display: none">
<div style="width: 300pt; text-align: center;">Uploading...</div>
<div style="width: 300pt; height: 20px; border: solid 1pt gray">
<div id="divProgress" runat="server" style="width: 1pt; height: 20px; background-color: Gray; display: none">
</div>
</div>
<div style="width: 300pt; text-align: center;">
<asp:Label ID="lblPercentage" runat="server" Text="Label"></asp:Label>
</div>
</div>
</div>
<br />
<asp:Label ID="Label1" runat="server" ForeColor="Red" Text=""></asp:Label>
</form>
<script language="javascript" type="text/javascript">
var size = 2;
var id = 0;
function ProgressBar() {
if (document.getElementById('<%=FileUpload1.ClientID %>').value != "") {
document.getElementById("divProgress").style.display = "block";
document.getElementById("divUpload").style.display = "block";
id = setInterval("progress()", 20);
return true;
}
else {
alert("Select a file to upload");
return false;
}
}
function progress() {
size = size + 1;
if (size > 299) {
clearTimeout(id);
}
document.getElementById("divProgress").style.width = size + "pt";
document.getElementById("<%=lblPercentage.ClientID %>").
firstChild.data = parseInt(size / 3) + "%";
}
</script>
protected void Button1_Click(object sender, EventArgs e)
{
// Do code here to saving a file from fileupload control
//FileUpload1.PostedFile.SaveAs("path");
System.Threading.Thread.Sleep(8000);
Label1.Text = "Upload successfull!";
}
Here is the source url - http://www.codeproject.com/Articles/26668/Showing-progress-bar-while-uploading-a-file-in-an
Guys I am using a jquery price range slider for getting Price range from user.But the problem is that the Price range selected by user on slider I have to use that in code behind.My code is like this:
My java script:
<script type="text/javascript">
//adding load class to body and hide page
document.documentElement.className += 'loadstate';
</script>
<script type ="text/javascript" >
var str1= document.getElementById("amt3").value;
var str2= document.getElementById("amt4").value;
document.getElementById("hf1").value = str1;
document.getElementById("hf2").value = str2;
</script>
</head>
My Html code is like this:
<asp:HiddenField ID="hf1" runat="server" />
<asp:HiddenField ID="hf2" runat="server" />
<div class="form-row row-fluid">
<div class="span12">
<div class="row-fluid">
<label class="form-label span4" for="slider">
Range slider</label>
<div class="span8">
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate >
<asp:HiddenField ID="HiddenField1" runat="server" />
<div id="slider-range" class="slider" >
</div>
<input type="text" id="amount1" style="border: 0; color: #ED7A53; font-weight: bold;
box-shadow: none;" />
<input type="text" id="amt3" style="border: 0; color: #ED7A53; font-weight: bold;
box-shadow: none;" />
<input type="text" id="amt4" name="amt4" style="border: 0; color: #ED7A53;
font-weight: bold; box-shadow: none;" />
</ContentTemplate>
</asp:UpdatePanel>
</div>
</div>
</div>
and My code Behind is like this:
protected void lnkFilter_Click1(object sender, EventArgs e)
{
string str= hf1.Value;
if (WebHelper.Cast(amt2.Value, 0) != 0)
{
Fill();
}
}
But the Problem is hf1 (hidden field) is getting empty string value.Please help me in this and suggest me a solution how to use selected range on jquery slider in code behind file.
You should move your hidden values inside your Update panel as they will not get posted back to the server on a partial update.