I am trying to publish images in Carousel. But Image not loading. Anyone can help will be highly appreciated. Following is the code:
carousel_test.aspx file code below. Here , through Rgallery, I am trying to display carousel images.
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="carousel_test.aspx.cs" Inherits="reader.carousel_test" %>
<!DOCTYPE html>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<link rel="stylesheet" href="css/style.css">
<!--Carousel -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<!--Carousel -->
<body>
<form id="form1" runat="server" style="font-size: small">
<div id="myCarousel" class="carousel slide">
<div class="carousel-inner">
<asp:Repeater ID="Rgallary" runat="server">
<ItemTemplate>
<div class="item" >
<div class="item active">
<asp:Image ID="Image1" runat="server" ImageUrl='<%# "ImageHandler.ashx?ImID="+ Eval("product_sell_code") %>' />
</div>
</div>
</ItemTemplate>
</asp:Repeater>
</div>
//This is used for manual navigation like for next or previous
<a class="carousel-control left" href="#myCarousel" data-slide="prev">‹</a>
<a class="carousel-control right" href="#myCarousel" data-slide="next">›</a>
</div>
</form>
</body>
<script type="text/javascript">
$(document).ready(function () {
$('.carousel').carousel({
interval: 2500
})
});
</script>
carousel_test.aspx.cs file code below. This is code file, where I am calling for loading image from database.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data;
using System.Data.OleDb;
using System.Data.SqlClient;
namespace reader
{
public partial class carousel_test : System.Web.UI.Page
{
string sq = ConfigurationManager.ConnectionStrings["readerConnStr"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bindslide();
}
}
public void bindslide()
{
SqlConnection connection = new SqlConnection(sq);
using (SqlCommand cmd = new SqlCommand("select product_sell_code from product_for_sell ", connection))
{
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
Rgallary.DataSource = ds;
}
Rgallary.DataBind();
connection.Dispose();
connection.Close();
}
}
}
ImageHandler.ashx.cs is the Image Handler File
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Services;
namespace reader
{
/// <summary>
/// Summary description for $codebehindclassname$
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class ImageHandler : IHttpHandler
{
SqlConnection connection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["readerConnStr"].ToString());
/* string strcon = ConfigurationManager.AppSettings["readerConnStr"].ToString(); */
public void ProcessRequest(HttpContext context)
{
string imageid = context.Request.QueryString["ImID"];
/* SqlConnection connection = new SqlConnection(strcon);*/
connection.Open();
SqlCommand command = new SqlCommand("select product_image from product_for_sell where product_sell_code=" + imageid, connection);
SqlDataReader dr = command.ExecuteReader();
dr.Read();
context.Response.BinaryWrite((Byte[])dr[0]);
connection.Close();
context.Response.End();
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
Here is the code. Please help
Related
Explain : I want to display data from database on google map but is shows that google API key is needed, I already put it inside script tag but still error is occured.I attached code of default.apsx page and default.aspx.cs page.
plaese help me our this issue.
Error : You need to set the Google Maps API Key
my code is:
//Default.aspx
<%# Register Assembly="GMaps" Namespace="Subgurim.Controles" TagPrefix="cc1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript" src = "https://maps.googleapis.com/maps/api/js?key=AIzaSyC6v5-2uaq_wusHDktM9ILcqIrlPtnZgEk&sensor=false">
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<cc1:GMap ID="GMap1" runat="server" Width="500px" Height="500px" />
</div>
</form>
</body>
</html>
//default.aspx.cs
using Subgurim.Controles;
using Subgurim.Controles.GoogleChartIconMaker;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GLatLng mainLocation = new GLatLng();
GMap1.setCenter(mainLocation, 14);
XPinLetter xpinLetter = new XPinLetter(PinShapes.pin_star, "H", Color.Blue, Color.White, Color.Chocolate);
GMap1.Add(new GMarker(mainLocation, new GMarkerOptions(new GIcon(xpinLetter.ToString(), xpinLetter.Shadow()))));
List<lOCATION> tblobj = new List<lOCATION>();
using (MapDATAEntities dbcontext =new MapDATAEntities())
{
tblobj = dbcontext.lOCATIONs.Where(i => i.country.Equals("india")).ToList();
}
PinIcon p;
GMarker gm;
GInfoWindow win;
foreach (var i in tblobj)
{
p = new PinIcon(PinIcons.truck, Color.Cyan);
gm = new GMarker(new GLatLng(Convert.ToDouble(i.lat), Convert.ToDouble(i.lng)),
new GMarkerOptions(new GIcon(p.ToString(), p.Shadow())));
win = new GInfoWindow(gm, i.city + " <a href='" + i.empImg + "'>Read more...</a>", false, GListener.Event.mouseover);
GMap1.Add(win);
}
}
}
}
When trying to register to my database I am receiving the "The name 'UName' does not exist in the current context" error.
Register.aspx:
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Register.aspx.cs" Inherits="Register" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Registration Page</title>
</head>
<body>
<p>This is the registration page</p>
Home | Register
<form id="form1" runat="server">
<div>
<p>Enter First Name :</p>
<p>
<asp:TextBox ID="UName" runat="server" Width="271px"></asp:TextBox>
</p>
<p>
<asp:Button ID="registerButton" runat="server" Text="REGISTER" OnClick="registerEventMethod" />
</p>
</div>
</form>
</body>
</html>
Register.aspx.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Register : System.Web.UI.Page
{
MySql.Data.MySqlClient.MySqlConnection conn;
MySql.Data.MySqlClient.MySqlCommand cmd;
String queryStr;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void registerEventMethod(object sender, EventArgs e)
{
registerUser();
}
private void registerUser()
{
String connString = System.Configuration.ConfigurationManager.ConnectionStrings["WebAppConnString"].ToString();
conn = new MySql.Data.MySqlClient.MySqlConnection(connString);
conn.Open();
queryStr = "";
queryStr = "INSERT INTO jamieobr_obecarrentals.users (Forename)" +
"VALUES('" + UName.Text + "')";
cmd = new MySql.Data.MySqlClient.MySqlCommand(queryStr, conn);
cmd.ExecuteReader();
conn.Close();
}
}
why am I getting this error? I have tried several solutions and all failed.
So I solved my own issue, the first initial issue was that I tried copying the .aspx file into a new solution, however this did not copy along the .aspx.designer.cs file therefore causing the problem.
However after trying to re write a fresh version manually which had a designer file with it I forgot to include the .cs file into the namespace of my solution therefore then generating a new problem.
However after including the .cs file into the namespace, hey presto, it worked!
I have asp.net web form and when Im trying to assing onclick event to a button I get following error:
Compiler Error Message: CS1061: 'ASP.webform1_aspx' does not contain a definition for 'Button1_Click' and no extension method 'Button1_Click' accepting a first argument of type 'ASP.webform1_aspx' could be found (are you missing a using directive or an assembly reference?)
Source Error:
Line 19: Line 20: Line 21:
Line 22:
Line 23:
ASP code is following:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="Form1" runat="server" method="post">
<div class="page">
<p>Persons</p>
<asp:Literal id="drpdwn" runat="server" />
<p>TransactionType</p>
<select id="sel" runat="server">
<option>bilance </option>
<option>liekākais parādnieks un aizdevējs</option>
<option>vidējais aizņēmuma lielums</option>
</select>
<asp:Button ID="Button1" runat="server" Text="Click Me" OnClick="Button1_Click" />
<table id="HTMLTable" width="300px;" runat="server">
<tr>
<td>
<b></b>
</td>
</tr>
</table>
</div>
</form>
</body>
<script type="text/javascript" >
var yourSelect = document.getElementById("sel");
var asdasd = yourSelect.options[yourSelect.selectedIndex].value;
</script>
</html>
And Codebehind is following:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Web.UI.HtmlControls;
namespace WebApplication1
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//int selectedIndex = (sel as HtmlSelect).SelectedIndex;
sel.Value.ToString();
SqlConnection cnn = new SqlConnection();
SqlDataReader rdr = null;
SqlCommand command = new SqlCommand();
cnn.ConnectionString = #"Server=localhost;Database=TildeTest;uid=AdminUser;pwd=AdminPwd;app=WebApplication1;";
DataSet ds = new DataSet();
DataTable dt = new DataTable();
string CommandText = "select * from persons";
command = new SqlCommand(CommandText);
command.CommandType = CommandType.Text;
//command.Connection = cnn;
try
{
cnn.Open();
command.Connection = cnn;
rdr = command.ExecuteReader();
if (rdr.HasRows)
{
drpdwn.Text = "<select>";
drpdwn.Text += "<option> </option>";
while (rdr.Read())
{
drpdwn.Text += "<option>" + rdr.GetString(1) + "</option>";
}
drpdwn.Text += "</select>";
}
else
{
Console.WriteLine("No rows found.");
}
rdr.Close();
}
catch (Exception ex)
{
Console.WriteLine(e.ToString());
}
finally
{
if (cnn.State == ConnectionState.Open)
cnn.Close();
}
}
void Button1_Click(Object sender,
EventArgs e)
{
// do something
}
}
}
you can change void Button1_Click to protected void Button1_Click and try.
Assuming you are using visual studio, double click the button from design view, then write the code behind inside the generated function. That should work.
Im using Microsoft Visual Studio 2012 as platform and i have created Web Forms Project
i have created data base file "SimpleDB.mdf" inside his "Table" folder i added new table called "Table" which has two columns - id and Name(string).What im trying is to insert string data into Name column of this table while calling server side function from javascript function.
This is the aspx.cs code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Web.Services;
namespace ProjectWWW
{
public partial class WebForm1 : System.Web.UI.Page
{
[WebMethod]
public static string InsertData(string ID){
string source = "Data Source=(LocalDB)\v11.0;Integrated Security=True;Connect Timeout=30";
SqlConnection con = new SqlConnection(source);
{
SqlCommand cmd = new SqlCommand("Insert into Table(Name) values('" + ID + "')", con);
{
con.Open();
cmd.ExecuteNonQuery();
return "True";
}
}
}
}
and this is the aspx code
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="ProjectWWW.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script>
function CallMethod() {
PageMethods.InsertData("hello", CallSuccess, CallError);
}
function CallSuccess(res) {
alert(res);
}
function CallError() {
alert('Error');
}
</script>
</head>
<body>
<header>
</header>
<div class="table" id="div1" > </div>
<form id="Form1" runat="server">
<asp:Button id="b1" Text="Submit" runat="server" onclientclick="CallMethod();return false;"/>
<asp:ScriptManager enablepagemethods="true" id="ScriptManager1" runat="server"></asp:ScriptManager>
</form>
</body>
</html>
So basically im expecting when the button submit is clicked the Table Column "Name" will be filled with "Hello" but nothing happens and the column stays empty(NULL)
Table is reserved word in T-SQL so i would suggest you to use [] square brackets to enclose the Table.
Try This:
SqlCommand cmd = new SqlCommand("Insert into [Table](Name)
values('" + ID + "')", con);
Suggestion: Your query is open to sql injection attacks.I would suggest you to use Parameterised Queries to avoid them.
Try This:
using(SqlConnection con = new SqlConnection(source))
{
using(SqlCommand cmd = new SqlCommand("Insert into [Table](Name)
values(#Name)", con))
{
con.Open();
cmd.Parameters.AddWithValue("#Name",ID);
cmd.ExecuteNonQuery();
return "True";
}
}
what i have done is login and the username appears in my masterpage in a label. what i need to do is if the logged in user has admin permission make visible controls on several child pages (including a gridview deletecontrol that is there on one child page). have be struggling to figure it out. just want to learn.
Is there a way to class all the controls under a class call admin and call from masterpage on checking user permission?
Loginpage code behind
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.Adapters;
public partial class login1 : System.Web.UI.Page
{
public void Page_Load(object sender, EventArgs e)
{
}
protected void LoginButton_Click(object sender, EventArgs e)
{
DataSet ds = new DataSet();
ds = WCGSQL.showdata("select * from Login where Username='" + UserName.Text + "' and Password='" + Password.Text + "'");
if (ds.Tables[0].Rows.Count != 0)
{
Session["Username"] = UserName.Text;
Response.Redirect("Home.aspx");
}
else
{
FailureText.Visible = true;
FailureText.Text = "Invalid Login";
}
}
}
App/code code behind
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public class WCGSQL
{
static SqlConnection con = new SqlConnection(#"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|WCG.mdf;Integrated Security=True;User Instance=True");
static public Boolean savedata(string qurt)
{
try
{
SqlCommand cmd = new SqlCommand(qurt, con);
con.Open();
cmd.ExecuteNonQuery();
return true;
}
catch
{
return false;
}
finally
{
con.Close();
}
}
static public DataSet showdata(string qurt)
{
DataSet ds = new DataSet();
try
{
SqlDataAdapter adp = new SqlDataAdapter(qurt, con);
adp.Fill(ds);
return ds;
}
catch
{
return ds;
}
}
}
You want to use the LoginView control. See ASP.NET Login Controls Overview to learn about the entire suite.
Example from MSDN:
<%# Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>ASP.NET Example</title>
</head>
<body>
<form id="form1" runat="server">
<p>
<asp:LoginStatus id="LoginStatus1" runat="server"></asp:LoginStatus></p>
<p>
<asp:LoginView id="LoginView1" runat="server">
<AnonymousTemplate>
Please log in for personalized information.
</AnonymousTemplate>
<LoggedInTemplate>
Thanks for logging in
<asp:LoginName id="LoginName1" runat="Server"></asp:LoginName>.
</LoggedInTemplate>
<RoleGroups>
<asp:RoleGroup Roles="Admin">
<ContentTemplate>
<asp:LoginName id="LoginName2" runat="Server"></asp:LoginName>, you
are logged in as an administrator.
</ContentTemplate>
</asp:RoleGroup>
</RoleGroups>
</asp:LoginView></p>
</form>
</body>
</html>
if (HttpContext.Current.User.IsInRole("member"))
{
//enable/disable here
}
Hey i'd done one application like this. What you need to do is make separate web-pages (i.e. after login pages) for both admin and other users. Then you can easily authenticate admin through his credentials and redirected to the respective page. There you can placed some controls according to the need.
And if your concern is to create an application like control-access board where admin can give permissions to modules to what to show on child pages of other users then let me know through your reply.