|
i want to set the menu items in center on hover event.
|
|
|
|
|
Hi I've been searching awhile but haven't found what I was looking for. I am trying to upload a file to SQL database using HTML5 <input type=file>. I have the html5 side done but am looking for a resource or example of server side code that will upload the file to a SQL server. I know I'll using httpwebrequest. Do I use a webservice (asmx file)? a handler (axhx file)? or something else?
Thank you!
John
|
|
|
|
|
A generic handler is probably the simplest option.
Use the Files property[^] of the context.Request object to read the uploaded files. This will return a collection of HttpPostedFile[^] objects. You can then use the InputStream property[^] to read the contents of the file.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks Richard, I think I'm missing something. I created a generic handler .ashx file but "Files" is not a property of context.Request. The error message on "Files = HttpRequest.Files" is "Reference to non-shared member requires object" Here is my code...
Imports System.Web
Imports System.Web.Services
Public Class Handler1
Implements System.Web.IHttpHandler
Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
Dim loop1 As Integer
Dim arr1() As String
Dim Files As HttpFileCollection
Files = HttpRequest.Files ' Load File collection into HttpFileCollection variable.
arr1 = Files.AllKeys ' This will get names of all files into a string array.
For loop1 = 0 To arr1.GetUpperBound(0)
context.Response.Write("File: " & Server.HtmlEncode(arr1(loop1)) & "<br>")
context.Response.Write(" size = " + Files(loop1).ContentLength + "<br />")
context.Response.Write(" content type = " + Files(loop1).ContentType + "<br />")
Next loop1
End Sub
ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property
End Class
What I am missing?
|
|
|
|
|
As the error says, the Files property is not a Shared property; it's an instance property. You need to use context.Request.Files instead.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks Richard! I figured it out!
for those curious, here is code that uses html5, jquery, javascript, and an asp.net handler to display selected image, upload image from client and save to SQL Server...
here is html..
<input type="file" id="upldFile" name="files[]" />
<input type="button" value="Add Sign" data-icon="plus" data-mini="true" id="btnAddSign">
here is javascript...
$('#upldFile').change(function (evt) {
var formData = new FormData();
var files = evt.target.files;
for (var i = 0, f; file = files[i]; i++) {
if (!file.type.match('image.*')) {
continue;
}
var thumbnail = URL.createObjectURL(file);
formData.append(file.name, file);
$('body').data('formdata', formData);
var span = document.createElement('span');
span.innerHTML = ['<img class="thumb" src="', thumbnail,
'" title="', escape(file.name), '"/>'].join('');
document.getElementById('list').insertBefore(span, null);
}
});
$('#btnAddSign').click(function () {
var xhr = new XMLHttpRequest();
var url = 'Handler1.ashx?requestid=' + $('body').data('requestid') + '&backcolor=' + $('#cmbBackColor').val() + '&textcolor=' + $('#cmbTextColor').val() + '&signshape=' + $('#cmbSignShape').val() + '&signsize=' + $('#cmbSignShape').val() + '&platematerial=' + $('#cmbPlateMaterial').val() + '&border=' + $('#sldBorder').val() + '&signtext=' + $('#txtSignText').val() + '&signquantity=' + $('#txtSignQuantity').val()
xhr.open('POST', url, true);
xhr.onload = function (e) {
};
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && xhr.status == 200) {
GetItems();
}
}
xhr.send($('body').data('formdata'));
});
Here is handler.ashx
Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
Dim requestid As String = context.Request.QueryString("requestid").ToString
Dim backcolor As String = context.Request.QueryString("backcolor").ToString
Dim textcolor As String = context.Request.QueryString("textcolor").ToString
Dim signshape As String = context.Request.QueryString("signshape").ToString
Dim signsize As String = context.Request.QueryString("signsize").ToString
Dim platematerial As String = context.Request.QueryString("platematerial").ToString
Dim signtext As String = context.Request.QueryString("signtext").ToString
Dim signquantity As String = context.Request.QueryString("signquantity").ToString
Dim border As Boolean = context.Request.QueryString("border").ToString
Dim Files As HttpFileCollection
Files = context.Request.Files
Dim uploadFiles As HttpFileCollection = Files
For i = 0 To uploadFiles.Count - 1
Dim postedFile As HttpPostedFile = uploadFiles(i)
Dim inStream As System.IO.Stream = postedFile.InputStream
Dim fileData As Byte() = New Byte(postedFile.ContentLength - 1) {}
inStream.Read(fileData, 0, postedFile.ContentLength)
Dim cnInsert As New SqlConnection(GetConnectionString("MyConnectionString"))
Dim cmdInsert As New SqlCommand
Dim da As New SqlDataAdapter
Dim lastupdate As New DataTable
Dim ds As New DataSet()
cnInsert.Open()
cmdInsert.Connection = cnInsert
cmdInsert.CommandType = CommandType.StoredProcedure
cmdInsert.CommandText = "spSRQSignsCustomInsert"
cmdInsert.Parameters.AddWithValue("@pSignSize", signsize)
cmdInsert.Parameters.AddWithValue("@pSignBackColor", backcolor)
cmdInsert.Parameters.AddWithValue("@pSignShape", signshape)
cmdInsert.Parameters.AddWithValue("@pSignText", signtext)
cmdInsert.Parameters.AddWithValue("@pSignQuantity", signquantity)
cmdInsert.Parameters.AddWithValue("@pSignTextColor", textcolor)
cmdInsert.Parameters.AddWithValue("@pBorder", border)
cmdInsert.Parameters.AddWithValue("@pPlateMaterial", platematerial)
cmdInsert.Parameters.AddWithValue("@pRequestID", requestid)
cmdInsert.Parameters.AddWithValue("@pRequestedImage", fileData)
cmdInsert.ExecuteNonQuery()
cnInsert.Close()
Next
End Sub
|
|
|
|
|
I am trying implement basic authentication method in web api and I currently in stage of reading user details from the database. I am expericing the following issue ('API.UserPro' does not contain a constructor that takes 0 arguments - error ) at the moment in the global.aspx:
protected void Application_Start()
{
GlobalConfiguration.Configuration
.MessageHandlers.Add(new BasicAuthMessageHandler()
{
PrincipalProvider = new UserPro()
});
public class UserPro : IProvidePrincipal
{
private User _userRepo;
public UserPro (User userRepo)
{
this._userRepo = userRepo;
}
public IPrincipal CreatePrincipal(string username, string password)
{
try
{
if (!_userRepo.Validate(username, password))
{
return null;
}
else
{
var identity = new GenericIdentity(username);
IPrincipal principal = new GenericPrincipal(identity, new[] { "Admin" });
return principal;
}
}
catch
{
return null;
}
}
}
}
Any advice or suggestion would be very helpful. Many thanks in advance.
|
|
|
|
|
As the error says, your UserPro class doesn't have a parameterless constructor. The only constructor in the code you posted takes an instance of the User class. To create an instance of the UserPro class, you'll need to pass in an instance of the User class.
GlobalConfiguration.Configuration.MessageHandlers.Add(new BasicAuthMessageHandler
{
PrincipalProvider = new UserPro(new User())
});
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thank you so much for your solution and help. Using your solution i was able to solve the issue.
Thank you very much once again.
Have a great day.
|
|
|
|
|
Hello Guys,
I have a simple asp.net page with an asp.net link button and asp.net content tag which point to a simple asp.net master page with an asp.net content place holder and a form tag. Here is the code of these two items:
Site.Master:
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site.master.cs" Inherits="WebApplication1.SiteMaster" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<form runat="server">
<asp:ContentPlaceHolder ID="MainContent" runat="server"/>
</form>
</body>
</html>
Default.aspx:
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:LinkButton ID="LinkButton1" runat="server">LinkButton</asp:LinkButton>
</asp:Content>
From some reason when we run this simple web application on one server the id the link bhutton get is MainContent_LinkButton1
and when we run this application on another server the id the link button get is _ctl0_MainContent_LinkButton1
Doese someone have an idia why we get the prefix _ctl0_ in a specific server and in another server we don't get it?
|
|
|
|
|
control IDs are changed so you don't have to worry about duplicate IDs on rendered HTML. It shouldn't also bother you as you still refer to the control's original ID in code. If for some reason rendered ID is important for you (i.e. you want to select it by jquery and can't use css class), you can add to the control the following property:
ClientIDMode="Static"
This will force asp.net to not change the contros's ID, but it is now your responsibility to make sure it is unique on the rendered HTML.
As for your question why on some servers there is _ctl0_ prefix - it may depend on OS version, IIS version, architecture and other factors.
--
"My software never has bugs. It just develops random features."
|
|
|
|
|
The server which gives you an ID of MainContent_LinkButton1 is running your application in a .NET 4.0 or higher AppPool. The server which gives you an ID of _ctl0_MainContent_LinkButton1 is running in a .NET 3.5 or earlier AppPool.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
But this is happen to us in two computers in which .net framework 4.5.1 is installed. How can this be?
|
|
|
|
|
You can have .NET 4.5.1 installed on a computer and still run an ASP.NET application in a .NET 3.5 AppPool. If you look at the "Advanced Settings" of the AppPool on the computer that's giving you the _ctl0_ prefix, you'll see the ".NET Framework Version" will be set to "v2.0" instead of "v4.0".
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
No, it is set to v4.0 and still giving _ctl0_ prefix
|
|
|
|
|
I am working on asp.net web application project. I want to develop a web page names as ApplyRulePage.aspx. User will apply rules (Rule has Start Time and End time) by uploading file. A Rule is defined for a period of time(From Start time to End time). lets say Rule is applied from a start time to end time(lets say from 14:56:59 March 1 2013 to 15:34:21 April 2013). User can apply multiple Rules if time span of Rules are mutually exclusive(means time is not clashing), So in this way We can apply any number of Rules for the User. But If lets say one Rule is applied and User wants to apply a new Rule and if time period of this new Rule is clashes with the Old Rule then We will give a message to the User that Old Rule will be deleted and new Rule will be applied and if time periods are not clashing it will so both Rule on Page.
So basic requirement is for a particular time period only one Rule should be applied.
My question here is how to implement this feature in asp.net. How well I can render page to the User so that it looks pretty good and For User it should be very easy to understand what exactly is happening on UI. If it could be achieved by javascript, jquery, ajax or some other programming, please let me know. If there is any link for a sample project or example please let me know. Sorry for such a stupid question actually I am learning asp.net by self and I have nobody to ask.
|
|
|
|
|
Whats the sql query for this table
the fields are : table name=Emp ,date_join current systemdate,
sal,city,state
pabitra behera
|
|
|
|
|
Let me Google that for you[^]
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
|
|
|
|
|
|
Hi
I wanted to insert my form into mysql database
Below is the code i used
protected void Submit_Click(object sender, EventArgs e)
{
MySqlConnection connection = null;
if(RadioButton1.Checked==true)
{
lblgender.Text= RadioButton1.Text;
}
else
{
lblgender.Text= RadioButton2.Text;
}
lblbusinessCat.Text=DropDownList1.SelectedValue;
using (connection = new MySqlConnection(ConfigurationManager.ConnectionStrings["MySQLConnectionString"].ConnectionString))
{
try
{
string sql = "INSERT INTO login(Username, Gender, Email, MobileNo, Category_Id, CompanyArea, CompanyName, CompanyNo, AltCompanyNo, Address)VALUES ('@Username', '@Gender', '@Email', '@MobileNo', '@Category_Id', '@CompanyArea', '@CompanyName', '@CompanyNo', '@AltCompanyNo', '@Address') ";
MySqlCommand cmd = new MySqlCommand(sql);
cmd.Parameters.AddWithValue("@Username", txtUserName.Text.Trim());
cmd.Parameters.AddWithValue("@Gender", lblgender.Text.Trim());
cmd.Parameters.AddWithValue("@Email", txtEmailId.Text.Trim());
cmd.Parameters.AddWithValue("@MobileNo", txtmobile.Text.Trim());
cmd.Parameters.AddWithValue("@Category_Id", lblbusinessCat.Text.Trim());
cmd.Parameters.AddWithValue("@CompanyArea", txtCompanyLoc.Text.Trim());
cmd.Parameters.AddWithValue("@CompanyName", txtCompanyname.Text.Trim());
cmd.Parameters.AddWithValue("@CompanyNo", txtCompNo.Text.Trim());
cmd.Parameters.AddWithValue("@AltCompanyNo", txtCompaltNo.Text.Trim());
cmd.Parameters.AddWithValue("@Address", txtCompAddress.Text.Trim());
cmd.Connection = connection;
connection.Open();
cmd.ExecuteNonQuery();
Session["username"] = txtUserName.Text;
Response.Redirect("Business_NewUpload.aspx", false);
//lblError.Text = "Data Saved";
}
catch (Exception ex)
{
Response.Write("An error occured: " + ex.Message);
//lblError.Text = ex.Message;
Response.Redirect("BusinessMoney_About.aspx", false);
}
finally
{
if (connection != null)
{
connection.Close(); //close the connection
}
}
}
}
i dont get any error , but my values are getting stored as @username,@gender
Please anyone help me.....It is very urgent for me to correct this
|
|
|
|
|
In MySZQL you simply use ? for placeholders in teh SQL statement - eg
string sql = "INSERT INTO login (Username, Gender, Email, MobileNo, Category_Id, CompanyArea, CompanyName, CompanyNo, AltCompanyNo, Address)VALUES (?,?,?,?,?,?,?,?,?) ";
|
|
|
|
|
I have a Gridview that has many pages. I order it by an ID number in descending order which is displayed. When I try to edit the row with my image button, the index I get does not match the row I clicked Edit on. How do I tie the row I clicked Edit on to the index the gvRowEditing method recieves? It gets a GridViewEditEventArgs object but that does not have a Command Argument that can tie the row to.
Thanks!
|
|
|
|
|
Look, my friend;
The edit command of the grid view control fires the events:
- RowEditing: where you set the
EditIndex property. this will load the editing template to render the row you wish to edit. - RowCancelingEdit: fired when edit is canceld.
- RowUpdating: fired when you click the update command. Here you make the actual editing action.
- RowUpdated: fired when the update is done.
you can refer to this page[^] for a good example
Help people,so poeple can help you.
|
|
|
|
|
hi there anyone can help me ....
i have created a database in which i am saving the id[int],name[varchar],visPic[image]
and i have created a search page for the visitor search by id and after searching griedview is visible for the data of visitor and when we click get details in gried view next page will open by auto fill id number, name , and pic in respective control. But i cannot bind the image in image control.Please help me out somebody i will be vry thnkful .....
|
|
|
|
|
You have two options.
If all of your users are using a recent browser, you can use a Data URI[^] to embed the image. It won't work in IE7 or earlier, and IE8 support is limited.
public static string GuessImageMimeType(byte[] data)
{
string result = null;
if (data != null && data.Length > 3)
{
if (data[0] == 71 && data[1] == 73 && data[2] == 70)
{
result = MediaTypeNames.Image.Gif;
}
else if (data[0] == 137 && data[1] == 80 && data[2] == 79)
{
result = "image/png";
}
else if (data[0] == 66 && data[1] == 77)
{
result = "image/bmp";
}
else
{
for (int index = 0; index < data.Length - 2; index++)
{
if (data[index] == 255 && data[index + 1] == 216 && data[index + 2] == 255)
{
result = MediaTypeNames.Image.Jpeg;
break;
}
}
}
}
return result;
}
public static string BuildImageUrl(byte[] data)
{
if (data == null || data.Length == 0) return null;
var sb = new StringBuilder("data:");
string mimeType = GuessImageMimeType(data);
if (!string.IsNullOrWhiteSpace(mimeType)) sb.Append(mimeType);
sb.Append(";base64,");
sb.Append(Convert.ToBase64String(data));
return sb.ToString();
}
<asp:Image runat="server"
ImageUrl='<%# BuildImageUrl((byte[])Eval("visPic")) %>'
/>
If you need support for older browsers, you'll need to create a generic handler to load and return the image based on the ID, and set the ImageUrl to point to that handler:
<asp:Image runat="server"
ImageUrl='<%# Eval("ID", "DisplayVisitorPicture.ashx?ID={0:D}") %>'
/>
There's an example of this approach here: Image Handling In ASP.NET[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|