Facing Issue with using System.Web.Routing - c#

I am using slideshow on my website. Its works fine when i disable the web routing.
When i enable the Web Routing on aspx pages, Slideshow working stops. I guess javascript not working after enabling Web routing.
protected void Application_Start(object sender, EventArgs e)
{
RegisterRoutes(RouteTable.Routes);
}
public static void RegisterRoutes(RouteCollection routes)
{
routes.MapPageRoute("CategoryRoute", "Category/{sCatId}", "~/Category.aspx",true);
routes.MapPageRoute("SubCategoryRoute", "SubCategory/{catid}", "~/SubCategory.aspx");
}
Routing works fine when i am using it, but working slideshow stops.
Below i am pasting slideshow code.
<div id="slider">
<div id="items">
<div>
<div style="width: 100%; margin: 0 0; height: 250px">
<img src="http://www.yepme.com/slider/1.jpg" alt="" width="100%" height="100%" />
</div>
</div>
<div>
<div style="width: 100%; margin: 0 0; height: 250px">
<img src="http://www.yepme.com/slider/2.jpg" alt="" width="100%" height="100%" />
</div>
</div>
<div>
<div style="width: 100%; margin: 0 0; height: 250px;">
<img src="http://www.yepme.com/slider/3.jpg" alt="" width="100%" height="100%" />
</div>
</div>
<div>
<div style="width: 100%; margin: 0 0; height: 250px;">
<img src="http://www.yepme.com/slider/4.jpg" alt="" width="100%" height="100%" />
</div>
</div>
</div>
</div>
Don't know what the problem is ? how it can be resolved.
I also used
<img src= '<%= Page.ResolveUrl("http://www.yepme.com/slider/4.jpg") %>' alt="" width="100%" height="100%" />
But it didn't work for me. Guys Help me !

Are your jpeg files delivered through a custom handler ?
If so, did you try adding some specific ignore for your slideshow ? Something like :
public static void RegisterRoutes(RouteCollection routes)
{
routes.Ignore("{*sliderimages}", new { sliderimages =#"slider/\d+\.jpg"});
routes.MapPageRoute("CategoryRoute", "Category/{sCatId}", "~/Category.aspx",true);
routes.MapPageRoute("SubCategoryRoute", "SubCategory/{catid}", "~/SubCategory.aspx");
}

Related

ASP.Net white page of death after submit

We have two ASP.NET (4.0) web applications running on IIS 8.5. Periodically, the users will try to log in and after submitting their credentials, the page will reload into a white screen.
The response size is 0 bytes and has a 200 status. The login page will reload and the HTML will be displayed, but when you submit the form the white page will be displayed. This is solved when the application pool is recycled.
I have checked the IIS logs and event viewer and there are no errors or warning related to this issue.
The code for the login.aspx page is below:
<%# Page Title="" Language="C#" MasterPageFile="~/login.Master" AutoEventWireup="true" CodeBehind="login.aspx.cs" Inherits="Driver.login1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<style type="text/css">
.has-error {
color: red;
}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<div class="form-group">
<span id="spnInvalidAccount" runat="server" visible="false" class="has-error">Invalid Credentials</span>
</div>
<div class="form-group has-feedback">
<asp:TextBox TextMode="SingleLine" ID="txtEmail" CssClass="form-control" placeholder="Box Number" runat="server"></asp:TextBox>
<span class="glyphicon glyphicon-envelope form-control-feedback"></span>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" CssClass="has-error" ControlToValidate="txtEmail" ErrorMessage="Careem Id Required" Display="Dynamic"></asp:RequiredFieldValidator>
</div>
<div class="form-group has-feedback">
<asp:TextBox ID="txtPassword" runat="server" CssClass="form-control" TextMode="Password" placeholder="Password"></asp:TextBox>
<span class="glyphicon glyphicon-lock form-control-feedback"></span>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" CssClass="has-error" ControlToValidate="txtPassword" ErrorMessage="Password Required" Display="Dynamic"></asp:RequiredFieldValidator>
</div>
<div class="row">
<!-- /.col -->
<div class="col-xs-8">
<span class="checkbox">
<div class="icheckbox_flat-red col-xs-1" aria-checked="false" aria-disabled="false" style="position: relative;">
<%--<asp:CheckBox ID="cbxRememberMe" runat="server" style="position: absolute; top: -20%; left: -20%; display: block; width: 140%; height: 140%; margin: 0px; padding: 0px; background: rgb(255, 255, 255); border: 0px; opacity: 0;" />--%>
<input id="Login1_RememberMe" runat="server" type="checkbox" name="Login1$RememberMe" style="position: absolute; top: -20%; left: -20%; display: block; width: 140%; height: 140%; margin: 0px; padding: 0px; background: rgb(255, 255, 255); border: 0px; opacity: 0;">
</div>
<label for="Login1_RememberMe" class="col-xs-9">Remember me</label>
</span>
</div>
<div class="col-xs-4">
<asp:Button ID="btnSubmit" Text="Sign In" runat="server" CssClass="btn btn-primary btn-block btn-flat" OnClick="btnSubmit_Click" />
</div>
<!-- /.col -->
</div>
</asp:Content>
And the code behind:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Driver
{
public partial class login1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Request.QueryString["action"] != null && Request.QueryString["action"] == "logout")
{
HttpCookie loggedInCookie = new HttpCookie("LoggedIn");
loggedInCookie.Expires = DateTime.Now.AddDays(-1);
Response.Cookies.Add(loggedInCookie);
}
else if (Request.Cookies["LoggedIn"] != null && Request.Cookies["LoggedIn"].Value != null)
{
Response.Redirect("default.aspx");
}
}
if (Request.Cookies["LoggedIn"] != null && Request.Cookies["LoggedIn"].Value != null)
{
Response.Redirect("default.aspx");
}
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
using (DriverEntities cnx = new DriverEntities())
{
string password = Global.EncryptPassword(txtPassword.Text);
if (cnx.Drivers.Where(x => x.BoxNumber == txtEmail.Text && x.Password == password).Any())
{
Driver driver = cnx.Drivers.FirstOrDefault(x => x.BoxNumber == txtEmail.Text && x.Password == password);
Car car = cnx.Cars.FirstOrDefault(x => x.Id == driver.CarId);
HttpCookie loggedInCookie = new HttpCookie("LoggedIn");
loggedInCookie.Value = driver.Id.ToString();
if (!Login1_RememberMe.Checked)
loggedInCookie.Expires = DateTime.Now.AddHours(8);
else
loggedInCookie.Expires = DateTime.Now.AddYears(1);
Response.Cookies.Add(loggedInCookie);
HttpCookie carCookie = new HttpCookie("MV_car");
carCookie.Value = car.Id.ToString();
Response.Cookies.Add(carCookie);
DateTime currentDate = DateTime.Now.AddDays(-1);
Response.Redirect("default.aspx");
}
else
{
spnInvalidAccount.Visible = true;
}
}
}
}
}
Some Remarks:
- I haven't been able to recreate this issue locally. This is only happening in the production environment.
- We use the same login page for a dozen other applications and we haven't had the same issue with them.
- The page is not redirecting to the default.aspx page.
- Customerrors is turned off so if there was an application error we would be able to see the exception screen

How can i apply bootstrap in my website? ASP.NET, C#

I have design a website which working fine regarding to design in desktop pc/laptop screen,but it's not working well in mobile and tablets devices.I'm using "responsive web design tester" google chorme add one to check this.It's middle contents changes.
How can i apply bootstrap in my website??I just include links of bootstrap or change the whole design.I'm beginner,I don't know how to apply "bootstrap".I have installed "Bootstrap" by using “Manage NuGet Package". Here is my solution explore snapshot
Here is my desktop view some content
Here mobile view
Here is my aspx code ,specific part of code in which the content not working well :
<section id="about">
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="title-area">
<h2 class="title">About us</h2>
<span class="line"></span>
<p>
UpSkill blends scientifically approved principles of learning and the best quality content to boost personal learning!
We aim to be the hub of quality education for personal growth and individual learning for a successful career!
</p>
</div>
</div>
</div>
</div>
</section>
<!-- end about -->
<!--Courses Start Here-->
<section id="our-team">
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="title-area">
<h2 class="title">Our Courses</h2>
<span class="line"></span>
<p>Search Courses as you want to study and Learn from our best Team!</p>
</div>
</div>
<div class="col-md-12">
<div class="our-team-content">
<div class="container">
<div class="row">
<!-- Start single Course -->
<div class="col-md-3 col-sm-6 col-xs-12">
<div class="single-team-member">
<div class="team-member-img">
<img src="assets\images\courses\linux.png" alt="linux img">
</div>
<div class="team-member-name">
<p style="position: relative; left: 7px; font-size: 25px;">Introduction to Linux </p>
<span style="position:relative; left:7px">CS250</span>
</div>
<p></p>
</div>
<!-- <div class="team-member-link">
<a class="read-btn wow fadeInUp" href="#"><font color="black"></font></a>
</div> -->
</div>
<!-- Start single Course -->
<!-- Start single Course -->
<div class="col-md-3 col-sm-6 col-xs-12">
<div class="single-team-member">
<div class="team-member-img">
<img src="assets\images\courses\asp-net.png" alt="asp.net img">
</div>
<div class="team-member-name">
<p style="position: relative; left: 7px; font-size: 25px;">Introduction to Asp.net</p>
<span style="position:relative; left:7px">CS250</span>
</div>
<p></p>
</div>
<!--<div class="team-member-link">
<a class="read-btn wow fadeInUp" href="#"><font color="black"></font></a>
</div>-->
</div>
<!-- Start single Course -->
<!-- Start single Course -->
<div class="col-md-3 col-sm-6 col-xs-12">
<div class="single-team-member">
<div class="team-member-img">
<img src="assets\images\courses\php.png" alt="php img">
</div>
<div class="team-member-name">
<p style="position: relative; left: 7px; font-size: 25px;">Introduction to PHP</p>
<span style="position:relative; left:7px">CS250</span>
</div>
<p></p>
</div>
<!--<div class="team-member-link">
<a class="read-btn wow fadeInUp" href="#"><font color="black"></font></a>
</div> -->
</div>
<!-- Start single Course -->
<!-- Start single Course -->
<div class="col-md-3 col-sm-6 col-xs-12">
<div class="single-team-member">
<div class="team-member-img">
<img src="assets\images\courses\html.png" alt="html img">
</div>
<div class="team-member-name">
<p style="position: relative; left: 7px; font-size: 25px;">Introduction to HTML5</p>
<span style="position:relative; left:7px">CS250</span>
</div>
<p></p>
</div>
</div>
<!-- Start single Course member -->
</div>
</div>
</div>
</div>
</div>
<br />
<button style="position:relative; left:1170px; color:black; font-size:18px; width:130px; height:60px;">See More</button>
</div>
</div>
</section>
"About" and "Our Courses" also working well in mobile devices,but problem with blow code.
Here is my bootstrap.css code :
.container {
padding-right: .9375rem;
padding-left: .9375rem;
margin-right: auto;
margin-left: auto;
}
.container::after {
display: table;
clear: both;
content: "";
}
#media (min-width: 544px) {
.container {
max-width: 576px;
}
}
#media (min-width: 768px) {
.container {
max-width: 720px;
}
}
#media (min-width: 992px) {
.container {
max-width: 940px;
}
}
#media (min-width: 1200px) {
.container {
max-width: 1140px;
}
}
.container-fluid {
padding-right: .9375rem;
padding-left: .9375rem;
margin-right: auto;
margin-left: auto;
}
.container-fluid::after {
display: table;
clear: both;
content: "";
}
.row {
margin-right: -.9375rem;
margin-left: -.9375rem;
}
.row::after {
display: table;
clear: both;
content: "";
}
.col-xs-1, .col-xs-2, .col-xs-3,
.col-xs-4, .col-xs-5, .col-xs-6,
.col-xs-7, .col-xs-8, .col-xs-9,
.col-xs-10, .col-xs-11, .col-xs-12,
.col-sm-1, .col-sm-2, .col-sm-3,
.col-sm-4, .col-sm-5, .col-sm-6,
.col-sm-7, .col-sm-8, .col-sm-9,
.col-sm-10, .col-sm-11, .col-sm-12,
.col-md-1, .col-md-2, .col-md-3,
.col-md-4, .col-md-5, .col-md-6,
.col-md-7, .col-md-8, .col-md-9,
.col-md-10, .col-md-11,
.col-md-12, .col-lg-1, .col-lg-2,
.col-lg-3, .col-lg-4, .col-lg-5, .col-lg-6,
.col-lg-7, .col-lg-8, .col-lg-9,
.col-lg-10, .col-lg-11, .col-lg-12,
.col-xl-1, .col-xl-2, .col-xl-3,
.col-xl-4, .col-xl-5, .col-xl-6,
.col-xl-7,.col-xl-8, .col-xl-9,
.col-xl-10, .col-xl-11, .col-xl-12 {
position: relative;
min-height: 1px;
padding-right: .9375rem;
padding-left: .9375rem;
}
.col-xs-1, .col-xs-2, .col-xs-3, .col-xs-4,
.col-xs-5, .col-xs-6, .col-xs-7,
.col-xs-8, .col-xs-9,
.col-xs-10, .col-xs-11, .col-xs-12 {
float: left;
}
.col-xs-1 {
width: 8.333333%;
}
.col-xs-2 {
width: 16.666667%;
}
.col-xs-3 {
width: 25%;
}
.col-xs-4 {
width: 33.333333%;
}
.col-xs-5 {
width: 41.666667%;
}
.col-xs-6 {
width: 50%;
}
.col-xs-7 {
width: 58.333333%;
}
.col-xs-8 {
width: 66.666667%;
}
.col-xs-9 {
width: 75%;
}
.col-xs-10 {
width: 83.333333%;
}
.col-xs-11 {
width: 91.666667%;
}
.col-xs-12 {
width: 100%;
}
How can i apply "Bootstrap" on my website?Which works well in every device.
Thanks..
There's a bit more to bootstrap than just dropping the files in (So you should spend a bit of time learning the basics), but have a look at this section to get your basic html:
http://getbootstrap.com/getting-started/#template
This will link the bootstrap javascript and css. Be sure to add any of your own javascript/css as well.
Then have a look at the overview and grid system at: http://getbootstrap.com/css/
This is how you choose the structure of your site using html as JustLearning mentioned. You'll probably be just putting your images in 1 row spanned across 4 columns.
The page looks bootstrapped to me but it depends on whether you meant you want your images to turn into links or made smaller into icons as that will be a new question. Responsive design is about the page fitting into the device and your page appears to fit although the images have been resized. Plus I don't see any MVC or C# or ASP.net so this is straight forward as it looks like you just have a basic HTML5 site. Here is a good link to get you started: http://docs.asp.net/en/latest/client-side/bootstrap.html

show asp.net progress bar for multiple operations

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

Not able to use javascript variable in code behind in C#

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.

How to retrieve URL off a button?

<div id="song_html" class="show1">
<div class="left">
<!-- info mp3 here -->
3.88 mb
</div>
<div id="right_song">
<div style="font-size: 15px;">
<b>Beatles - Hey Jude mp3</b></div>
<div style="clear: both;">
</div>
<div style="float: left;">
<div style="float: left; height: 27px; font-size: 13px; padding-top: 2px;">
<div style="float: left; width: 27px; text-align: center;">
<a href="javascript:void(0)" onclick="showPlayer(161498180, 'b7f231500894c321c0a7739802edff16965eb111', 'beatles', 'hey+jude')"
rel="nofollow" id="lk161498180" class="play_now">Play</a></div>
<div style="margin-left: 8px; float: left;">
<a href="http://dc109.4shared.com/img/1038702204/8ffe01b/dlink__2Fdownload_2FxAdbDSb4_3Ftsid_3D20111224-60034-
aa918a50/preview.mp3" rel="nofollow" target="_blank" style="color: green;">Download</a></div>
<div style="margin-left: 8px; float: left;">
<a href="javascript:void(0)" onclick="showEmbed(161498180,
'b7f231500894c321c0a7739802edff16965eb111')" rel="nofollow" id="em161498180" class="embed">
Embed</a></div>
<div style="margin-left: 8px; float: left;">
<a href="http://www.ringtonematcher.com/go/?sid=WDLL&artist=beatles&song=hey+jude"
rel="nofollow" target="_blank" style="color: red;" title="Send Beatles - Hey Jude Ringtone to your Cell">
Send Ringtone</a></div>
<div style="clear: both;">
</div>
</div>
<div id="player161498180" style="float: left; margin-left: 10px;" class="player">
</div>
</div>
<div style="clear: both;">
</div>
</div>
<div style="clear: both;">
</div>
</div>
I would love to know how to retrieve the link 'http://dc109.4shared.com/img/1038702204/8ffe01b/dlink__2Fdownload_2FxAdbDSb4_3Ftsid_3D20111224-60034-aa918a50/preview.mp3'.
I asked around other forums and people numerous times but I still do not understand/not working.
It is a must that I get it through class "show1" as there are other classes.
If you do this often, you can use the third-party (open source) library HtmlAgilityPack and get your value using XPath (for which there are many resources online).
Once I create the HtmlDocument (by downloading the page using HtmlWeb.Load) I would use the following to get the URL:
String theLink = myDoc.DocumentNode.SelectSingleNode("//div[#class='show1']//a[.='Download']").Attributes["href"].Value;
If the only unique thing is the text, you can do it this way using jQuery:
var href = $('a:text("Download")').attr('href');
Hope this helps
you can do get it using an html-parsing, as HtmlAgilityPack.
simple example:
var doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(html);
var nodes = doc.DocumentNode.SelectNodes("//a[.='Download']");
var link = nodes[0].Attributes["href"].Value;
I believe that you is getting this HTML from 4shared page, you can use the DownloadString method from WebClient class for get the HTML.
there more easy way to do it,using the API.

Categories