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.
Related
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
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
Bootstrap has the following CSS:
.form-horizontal .control-label {
float: left;
width: 160px;
padding-top: 5px;
text-align: right;
}
.form-horizontal .controls {
*display: inline-block;
*padding-left: 20px;
margin-left: 180px;
*margin-left: 0;
}
It makes my form look like this:
The labels are way off to the right.
Here is how I build the form:
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<div id="kez_header">
<table class="style1">
<tr>
<td>
<h4> Add Group
</h4>
</td>
<td align="right" valign="middle">
</td>
</tr>
</table>
<div id="new_group_view" class="form-horizontal">
<form class="form-horizontal" method="POST" action="/yourownpoet/web/app_dev.php/register/">
<div class="control-group">
<label class="control-label control-label-me required" for="fos_user_registration_form_email" placeholder="Email">Email:</label>
<div class="controls">
<input id="fos_user_registration_form_email" class="text-style" type="email" placeholder="Email" required="required" name="fos_user_registration_form[email]">
<div placeholder="Password" id="fos_user_registration_form_plainPassword"></div>
</div>
</div>
<div class="control-group">
<label class="control-label required" for="fos_user_registration_form_plainPassword_Enter Password: ">Enter password: </label>
<div class="controls">
<input type="password" required="required" name="fos_user_registration_form[plainPassword][Enter Password: ]" id="fos_user_registration_form_plainPassword_Enter Password: " class="text-style">
</div>
</div>
<div class="control-group">
<label class="control-label required" for="fos_user_registration_form_plainPassword_Verify Password: ">Verify password: </label>
<div class="controls">
<input type="password" required="required" name="fos_user_registration_form[plainPassword][Verify Password: ]" id="fos_user_registration_form_plainPassword_Verify Password: " class="text-style">
</div>
</div>
</form>
</div>
</div>
</asp:Content>
How can I get this normal so that the labels start more like here:
http://bootstrap.stage42.net/doc/forms
Thanks
.form-horizontal .control-label width specifies the "how far would be last character of the label text from the left side of the parent container".
.form-horizontal .controls margin-left specifies the "how far would be left border of the field from the left side of the parent container".
This is simplified explanation but should give you enough understanding to take control over your styles.
So you should adjust .form-horizontal .control-label width and .form-horizontal .controls margin-left values proportionally, to move fields and labels inside the container. Proportionally because "space" between label and field should be preserved. Here is example:
.form-horizontal .control-label {
float: left;
width: 120px; /* changed from 160px to 120px */
padding-top: 5px;
text-align: right;
}
.form-horizontal .controls {
*display: inline-block;
*padding-left: 20px;
margin-left: 140px; /* changed from 180px to 140px */
*margin-left: 0;
}
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");
}
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>