|
Thanks a lot for all your help, jkirkerx.
I am beginning to think this is not even possible.
I have looked at several examples online and it seems it is just intended to display it and not do anything else with it.
So far, nothing I tried has worked.
Your off the top of your head examples have lots of errors I don't even know how to begin to fix them.
|
|
|
|
|
It can be done. We do this on a volunteer basis, we don't get paid. I'm not a retired person, I'm actually working on my jobs that I have to get finished while I'm trying to help you.
Your in the learning phase, and you don't quite understand HTML and the DOM, and how Java Script is just a DOM manipulator.
This happens with programmers that know how to write code, but don't know HTML very well, and downplays the significance of HTML as a language. PHP is classic for this. I see PHP programmers write elaborate code to generate HTML, instead of just writing a HTML page, with a little PHP to generate a little bit of HTML.
|
|
|
|
|
[EDIT]
I fixed your code, and now it works.
I don't really code in c#, and can't figure out why I have to click the button twice to populate the blue textbox, the postback results of the client script. Maybe someone else can give me some insight into this.
but like I said, I didn't see any asp.net in your first post, so it really seems like a javascript issue.
In hindsight, it looks you you pasted a bunch of code from the inter webs on to a web form, expecting it to work, without solid knowledge of how java script works, and how to adjust asp.net to it for the postback value to do whatever you need to do with it.
I can tell that you have very little experience with client scripting and asp.net, and could use a little more time and practice on that subject.
Like I said last night, it was just concept code, you were not suppose to copy and paste it into your work. You were suppose to see the difference and type that into your project.
<%@ Page Language="C#" AutoEventWireup="true" %>
<!DOCTYPE html>
<script runat="server">
protected void bt_search_Click(object sender, EventArgs e)
{
if (Page.IsPostBack)
{
String m_results = txt_results.Text;
txt_postback.Text = m_results;
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAA7j_Q-rshuWkc8HyFI4V2HxQYPm-xtd00hTQOC0OXpAMO40FHAxT29dNBGfxqMPq5zwdeiDSHEPL89A" type="text/javascript"></script>
<script type="text/javascript">
var geocoder, location1, location2;
function initialize() {
geocoder = new GClientGeocoder();
}
function showLocation() {
var vFlag = true;
geocoder.getLocations(document.getElementById('txt_address1').value, function (response) {
if (!response || response.Status.code != 200) {
alert('Sorry, we were unable to geocode the first address');
vFlag = false;
}
else {
location1 = { lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address };
geocoder.getLocations(document.getElementById('txt_address2').value, function (response) {
if (!response || response.Status.code != 200) {
alert('Sorry, we were unable to geocode the second address');
vFlag = False;
}
else {
location2 = { lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address };
calculateDistance();
}
});
}
});
return vFlag;
}
function calculateDistance() {
try {
var glatlng1 = new GLatLng(location1.lat, location1.lon);
var glatlng2 = new GLatLng(location2.lat, location2.lon);
var mdistance = glatlng1.distanceFrom(glatlng2, 3959).toFixed(1);
var mResults = '' +
'Address 1: ' + location1.address + '\r\n' +
'Address 2: ' + location2.address + '\r\n' +
'Distance: ' + mdistance + ' miles (or ' + mdistance + ' kilometers)';
document.getElementById('txt_results').value = mResults;
}
catch (error) {
alert(error);
}
}
</script>
</head>
<body onload="initialize()">
<form runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel ID="up_geoAddress" runat="server" ChildrenAsTriggers="False" ClientIDMode="Static" UpdateMode="Conditional">
<ContentTemplate>
<div style="width: 650px; display: block; text-align: left; margin: 6px;">
<asp:TextBox ID="txt_address1" runat="server" value="" CssClass="address_input" Style="Width: 80%;" ClientIDMode="Static"></asp:TextBox>
<asp:TextBox ID="txt_address2" runat="server" value="" CssClass="address_input" Style="Width: 80%;" ClientIDMode="Static"></asp:TextBox>
</div>
<div style="width: 650px; display: block; text-align: left; margin: 6px;">
<asp:Button ID="bt_search" runat="server" Text="Search" OnClick="bt_search_Click" style="width: 80%;" OnClientClick="return showLocation();" />
</div>
<div style="width: 650px; height: 128px; display: block; text-align: left; line-height: 128px;">
<asp:TextBox ID="txt_results" runat="server" style="width: 80%; height: 96px; border: solid 1px rgb(255,0,0);" ClientIDMode="Static" TextMode="MultiLine"></asp:TextBox>
</div>
<div style="width: 650px; height: 128px; display: block; text-align: left; line-height: 128px;">
<asp:TextBox ID="txt_postback" runat="server" style="width: 80%; height: 96px; border: solid 1px rgb(0,0,255);" ClientIDMode="Static" TextMode="MultiLine"></asp:TextBox>
</div>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="bt_search" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
</form>
</body>
</html>
modified 6-Dec-14 18:37pm.
|
|
|
|
|
jkirkerx,
I THANK YOU so much for your assistance but more importantly.
I have been extremely fortunate and blessed to work with people who demonstrate a great deal of patience with determination to help someone else succeed.
I really appreciate it.
About asp.net, no I am not a newbiew at all.
There are two things I can say I am good at; asp.net and sql are two of them.
As for Javascript, yes, I am not very good there.
Having said that, usually, before I post, I scoured the web looking for snippets or samples to use.
So, when I post, I post because I tried to solve it myself.
As I stated earlier, I was looking for a way to give us the ability to calculate mileage between two locations.
My googling took me to the sample Javascript I posted. Yes, you are right, the Javascript is mine but I tested it and it works.
However, I was looking for a way to use it with Multiview control.
I did mention that remember?
With multiview control, you have view1, view2, viewN.
In my case, I have view1 called vwPersonalData.
With this, users enter all their information and when they click NEXT, they are taken to view2 called vwPreviewData.
As the name suggests, they can preview the information they entered in vwpersonalDate.
If something is not right, they go back, correct it then try again.
If all is well, they click SUBMIT to submit to the database.
Everything works except this javascript bit.
I didn't want to dump all of that code here.
So, I started with Javascript per your suggestion so I can go one step at a time.
I am about to try to integrate your solution with multiview controls and see if i can do it.
Again, you are God sent and I thank you very much.
Be back with results.
|
|
|
|
|
Hi jkirkerx,
I know you have probably reached the end of your support and I can clearly understand it.
I have tested your code and it works exactly like you described it.
I am going to try to see if I can figure out another way to preview data without using multiview.
Until that happens, this is still not going to be of much help, unfortunately.
You have been great and I thank you very much.
|
|
|
|
|
I am trying to call a web service function within my own ASP.net (code behind) using AJAX on the page.
Once i push the button to execute the JS/AJAX/codebehind - I got an error.
[b]POST [url]http://************/admin/Admin.aspx/getDBInformation[/url] 500 (Internal Server Error)[/b]
This is my code below that I am currently using:
[code]
<webmethod> _
Public Shared Function getDBInformation() As String
loadDBData()
Return JsonConvert.SerializeObject(dbInfo, System.Xml.Formatting.Indented)
End Function
End Class
[/code]
The code behind looks like this:
[code]
Imports System.DirectoryServices
Imports System.Security.Principal
Imports System.Net
Imports System.Drawing
Imports System.IO
Imports System.Data.SqlClient
Imports System.Web.Services
Imports Newtonsoft.Json
Partial Class _Default
Inherits System.Web.UI.Page
Dim dbStoredData As dbData
Shared dbInfo As New List(Of dbData)
Dim sqlQ As SqlCommand = Nothing
Dim conn As SqlConnection = Nothing
Dim reader As SqlDataReader = Nothing
Dim strconnstring As String = ""
Shared theQuery As String = "Server=*******,1433;Database=**********;User Id=*******;Password=*********;"
Private Class dbData
Public veID As String = ""
Public veDate As String = ""
Public lastUpdated As String = ""
Public updatedBy As String = ""
End Class
[SOME MORE CODE BETWEEN HERE THAT WAS LEFT OUT]
Public Sub loadDBData()
conn = New System.Data.SqlClient.SqlConnection(strconnstring)
conn.Open()
theQuery = _
"SELECT * " & _
"FROM downTable " & _
"ORDER BY veID DESC"
sqlQ = New SqlCommand(theQuery, conn)
reader = sqlQ.ExecuteReader
dbInfo.Clear()
While reader.Read()
dbStoredData = New dbData()
dbStoredData.veID = EscapeLikeValue(reader("veID").ToString())
dbStoredData.veDate = EscapeLikeValue(reader("veDate").ToString())
dbStoredData.lastUpdated = EscapeLikeValue(reader("lastUpdated").ToString())
dbStoredData.updatedBy = EscapeLikeValue(reader("updatedBy").ToString())
dbInfo.Add(dbStoredData)
End While
sqlQ = Nothing
conn.Close()
conn = Nothing
End Sub
<webmethod> _
Public Shared Function getDBInformation() As String
loadDBData()
Return JsonConvert.SerializeObject(dbInfo, System.Xml.Formatting.Indented)
End Function
End Class
[/code]
How can I correct this issue so that I am able to cal
|
|
|
|
|
I'm not quite understanding what your trying to achieve here.
So you click on a button, and run a client script using jquery or javascript ajax request to your web service?
And the web service completely bombs resulting in a server error 500?
|
|
|
|
|
Where's your JavaScript code?
Also, put a breakpoint in your C# webmethod and see if it is even hitting the C# code.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
I'm getting "System.OutOfMemoryException in mscorlib.dll" exception in a View when using DisplayTemplate. I've simplified my code to this:
@model IEnumerable<T>
@{
Layout = null;
}
@{int i = 0;}
@foreach (var item in Model)
{
i += 1;
@Html.DisplayFor(modelItem => item.dsk_distancia, "distancia");
@Html.DisplayFor(modelItem => item.dsk_eurom2,"entero");
}
Where the DisplayTemplates "distancia" and "entero" goes as follows.
distancia.cshtml
@model double?
@Model.Value.ToString("F0") m.
entero.cshtml
@model double?
@Model.Value.ToString("F0")
The problem happens when the number of items increases. It works fine when the IEnumerable has less items but stops working with i>600 items or so.
I've detected that the problem is in the DisplayTemplate, because if I just use
@Html.DisplayFor(modelItem => item.dsk_distancia);
@Html.DisplayFor(modelItem => item.dsk_eurom2);
or
@item.dsk_distancia;
@item.dsk_eurom2;
then the exception is not thrown
|
|
|
|
|
I'm not extremely familiar with MVC, as I just started using it regularly a few months ago. However, I imagine this occurs because it's loading the display template into memory for each and every item. Have you tried passing a collection of dsk_distancia and dsk_eurom2 into your display templates, and looping the collection of "double?" objects in the templates, instead of looping in the view?
djj55: Nice but may have a permission problem
Pete O'Hanlon: He has my permission to run it.
|
|
|
|
|
I have a javascript that calculates mileage between two locations.
Once calculation is done, From location, To location and total mileage are displayed.
This works fine.
The issue that I am having is that I can't seem to get these values to display on another multiview control.
Here are relevant code:
//Javascript. This is what display the From, To, locations and total mileage
function initialize() {
geocoder = new GClientGeocoder();
gDir = new GDirections();
GEvent.addListener(gDir, "load", function() {
var drivingDistanceMiles = gDir.getDistance().meters / 1609.344;
var drivingDistanceKilometers = gDir.getDistance().meters / 1000;
document.getElementById('results').innerHTML = 'From: ' + location1.address + '<br />To: ' + location2.address + '<br />Driving Distance: ' + drivingDistanceMiles.toFixed(2) + ' miles ';
});
}
body id="top" onload="initialize()" class="page page-id-298 page-template-default stretched open_sans open_sans ">
<form id="form1" onsubmit="showLocation(); return false;" runat="server" class="ajax_form">
<asp:MultiView ID="myMultiView" ActiveViewIndex="0" runat="server">
<asp:View ID="vwPersonalData" runat="server">
...
...
</asp:View>
<asp:View ID="vwPreview" ActiveViewIndex="0" runat="server">
..
..
</asp:View>
</asp:MultiView>
<p id="results" runat="server" style="display:none"></p>
<asp:Button ID="btnBack" runat="server" Text="< Back " OnClick="btnBack_Click" />
<asp:Button ID="btnNext" runat="server" Text="Next >" OnClick="btnNext_Click" />
<asp:Button ID="btnSend" runat="server" Text="Send request" OnClick="btnSend_Click" />
</form>
All I am trying to do is make the values of results control ID not visible, but make it visible in the vwPreview control ID so I can grab the values in codebehind.
How do I do this?
Thanks a lot in advance
|
|
|
|
|
In MultiView, one 1 view renders at a time. So, controls of other view will not be available via client side.
As a workaround, you can use a hidden variable to store value and set it at server side to the corresponding control.
Life is a computer program and everyone is the programmer of his own life.
|
|
|
|
|
Anurag, thank you very much for your response.
Can you please give me an example of how you can use hidden variable in this instance?
|
|
|
|
|
can anyoen tell me when i use file upload in asp.net.how to rename file with id..its very urgent..plz
|
|
|
|
|
|
Simple - just use the ID to construct the file name you pass to the SaveAs method[^].
The FileUpload control does not automatically save a file to the server after the user selects the file to upload.
...
The code that you write to save the specified file should call the SaveAs method, which saves the contents of a file to a specified path on the server.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
if (FileUpload1.HasFile)
{
string s = hidVal.Value.ToString();
string link = hidsymp.Value.ToString();
lblimg_error.Text = "";
string filename = Path.GetFileName(FileUpload1.PostedFile.FileName);
string imagepath = ConfigurationManager.AppSettings["ImagePath"].ToString();
var logoimage = Path.Combine(imagepath, filename);
string extension = Path.GetExtension(filename).ToLower();
System.Drawing.Image img = System.Drawing.Image.FromStream(FileUpload1.PostedFile.InputStream);
int height = img.Height;
int width = img.Width;
FileUpload1.SaveAs(logoimage);
}
so upload file in folder
if you want to rename file when upload then store file name in one string and change string value and save changable string name
|
|
|
|
|
Why have you replied to me instead of the person asking the question?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Can we access a scanner(which is at client environment) from the client browser using ASP.Net?
I see some articles that we can do it using ActiveX.
Can some have any example.
|
|
|
|
|
I don't believe JavaScript can do it. I know my credit union's app for scanning checks uses Java so that may be the other route you need to go. JavaScript can't access local system resources so you need something like ActiveX or Java that can.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
Hi there! what a pleasure to join up to this forum
I've been working on making a product more secure and I've noticed when sniffing the network I can see passwords being posted via the form on Login.aspx, I would of thought there is a way to hash the password prior to form post, I've done some searching with no luck so far.
Thanks.
|
|
|
|
|
You probably mean encryption - hash is one way...
Anyway there is no use of hashing/encrypting data before post. If hacker has access to the client he can see the data before hash/encryption too!
The reason you can see the plain data is:
1. You run sniffing software (what do you use) on the client or server. That's (hopefully not the way hacker does it)
2. You do not use secure protocols, like HTTPS...
Skipper: We'll fix it.
Alex: Fix it? How you gonna fix this?
Skipper: Grit, spit and a whole lotta duct tape.
|
|
|
|
|
Thanks, I was planning on using a hashing method rather than encryption as encryption could be undone if you knew the algorithm/keys etc, hashing could be matched but not undone, this gets me some where for securing the password without SSL, from the research done today I may just go SSL.
|
|
|
|
|
In most cases there is an advantage to NOT to invent the wheel ...
Skipper: We'll fix it.
Alex: Fix it? How you gonna fix this?
Skipper: Grit, spit and a whole lotta duct tape.
|
|
|
|
|
The problem is that hashing the password on the client doesn't solve anything, and can actually make your application less secure.
You want to hash the password on the client in case someone can sniff the traffic, so that they won't be able to see the password. But if they can sniff the traffic, they don't need to see the password; they can just submit the password hash instead, since that's what your server is expecting.
Worse, if they managed to get hold of your database of password hashes, they wouldn't need to try to crack them; they could just submit the hashes as if they were plain-text passwords.
SSL is definitely the way to go. Let the infrastructure protect your passwords in-flight, and leave the hashing on the server where it belongs.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|