Oxiegen 88 Basically an Occasional Poster Featured Poster

Ok. Now I'm back from the holidays and could check my code. I found that I missed a quote-mark. Now there are no errors, but there still seem to be something odd happening.

In the screenshot, in the attached image, you can see two dynamically created forms marked form1 and form2.
After the calls to the functions objectify and JSON.stringify the alert show the information marked in a green rectangle.
That's not right considering that each form has a number of fields and should be created as an "array".

This is my complete javascript code for adding forms, objectify and such.

<script type="text/javascript" src="js/json2.js"></script>
<script type="text/javascript">
var appInc = 0;
var rowInc = 0;
var On_Error = false;
								    
function addRow(r){ 
var root = r.parentNode;//the root 
var allRows = root.getElementsByTagName('tr');//the rows' collection 
var cRow = allRows[0].cloneNode(true)//the clone of the 1st row 
var cInp = cRow.getElementsByTagName('asp:TextBox');//the inputs' collection of the 1st row 
for(var i=0;i<cInp.length;i++) {//changes the inputs' names (indexes the names) 
cInp[i].setAttribute('name',cInp[i].getAttribute('name')+'_'+(allRows.length+1)) 
} 
root.appendChild(cRow);//appends the cloned row as a new row 
}
			
function addAppartement() {
appInc++;
var appTable = document.getElementById("appTable");
var a = document.createElement('div');
a.setAttribute("id", "a" + appInc);
appTable.appendChild(a);

var html = '<form name="form' + appInc + '" action="#">\n';
html += '<table>\n';
html += '<tr>\n';
html += '<td class="td" vAlign="top" align="center" width="60"><input id="txtAppNr' + appInc + '" style="width: 44px" type="text"></td>\n';
html += '<td class="td" vAlign="top" align="center" width="50"><input id="txtFloor' + appInc + '" style="width: 44px" type="text"></td>\n';
html += '<td class="td" vAlign="top" align="center" width="50"><input id="txtUnitPlac' + appInc + '" …
Oxiegen 88 Basically an Occasional Poster Featured Poster

I'm sorry. I haven't had the chance to try anything today.
But as soon as I do, I'll post my findings.

Oxiegen 88 Basically an Occasional Poster Featured Poster

Yes, actually I did. But I'll have to look it over again.

The weird part is that when I debug using Firebug you can choose what js-script to debug and step through and I can clearly see the file and path. But in Firebug, the code of 'json2.js' doesn't contain any javascript code.

Oxiegen 88 Basically an Occasional Poster Featured Poster

Ok. So i managed to use the code snippet you gave me which resulted in a javascript object. It gave me a happy.

This is what i came up with:

function somename() {
                var o = objectify();
                var jsonString = JSON.stringify(o); // This line gets halted and displays a 'Undefined' error
                <ajaxcode>.CB_Function(jsonString,ServerSide_Callback2);
}

function objectify() {
	var o = {};
	var frms = document.forms;
	var formID = 1;
	var id = 1;
 
for (i = 0, maxI = frms.length; i < maxI ; i++) {
	if (frms[i].name == 'form' + formID) {
		var frm = frms[i];
		var elms = frm.elements;
		var tmp = {};
      
		for (var j = 0, maxJ = elms.length; j < maxJ; j++) {
			var el = elms[j];
			tmp[el.name] = el.value;
		}
		o[frm.name] = tmp;
		formID++;
	}
}
return (o);
}

I'm now trying to use the json script from json.org in order to create a json string.
The script has the function stringify that's supposed to return a json string from a javascript object.
But everytime I get to that line all I get is undefined and my script just dies.

See anything wrong?

Oxiegen 88 Basically an Occasional Poster Featured Poster

Everything about JSON looks interesting and workable.
But I'm new to JSON and used to passing information between functions using arguments. So, I'm gonna need a little hand-holding and guidance here. :)

On server-side i'm using AjaxPro by Michael Schwartz, which has built-in features for parsing JSON. And on client-side i've just added the json.js script found on json.org.

This is what I would like to do:
Build a JSON object on client-side filled with information from a dynamically created form (already working) that is then passed to server-side.
All examples i've read so far has been about creating the object/string on server-side and passing it to client-side.

The number of "sections" in the object is dependent on the number of dynamically created "form-rows", but each section will contain an array with a fixed size of 9 key/value pairs. As indicated on my first post.

Could you help me with a code-snippet on how to create that object in this manner?

Oxiegen 88 Basically an Occasional Poster Featured Poster

JSON look promising. I like the fact that it can contain an array.
But how to create a dynamic JSON object containing multiples.

My guess would be that the object needs to have the form:

var myJSONObject = {"bindings1": [
        {"ircEvent": "PRIVMSG", "method": "newURI", "regex": "^http://.*"},
        {"ircEvent": "PRIVMSG", "method": "deleteURI", "regex": "^delete.*"},
        {"ircEvent": "PRIVMSG", "method": "randomURI", "regex": "^random.*"}
    ],"bindings2": [
        {"ircEvent": "PRIVMSG", "method": "newURI", "regex": "^http://.*"},
        {"ircEvent": "PRIVMSG", "method": "deleteURI", "regex": "^delete.*"},
        {"ircEvent": "PRIVMSG", "method": "randomURI", "regex": "^random.*"}
    ], <and so on>
};

Am I right?
And how would I go about to access these values from codebehind? (ASP.NET)

Oxiegen 88 Basically an Occasional Poster Featured Poster

I'll look into it. Thanks.

Oxiegen 88 Basically an Occasional Poster Featured Poster

If the database was to be openly accessible *shudder*, albeit with a username and password.
Then you can most likely access the database with javascript and odbc (jdbc?).
If that is the case then no server-side scripting would be needed.

Oxiegen 88 Basically an Occasional Poster Featured Poster

Hi, all!

Here's another one that's starting to boggle my mind.

I have a form that, with a button, adds a bunch of text-fields in a tablerow.
For every press of the button another row is added. This works in both IE and FF. No probs.

When pressing another button, Register, the information in the form is to be stored in a db.
In the javascript funktion assigned to this button I have a loop that goes through the dynamically created rows of text-fields, and stores the values in variables.
These vars is then passed to an ajax-function.

I have tried with calling the function once in every iteration of the loop. But if you have a bunch or rows, 9 or more, only a few rows of information is stored, 3 or less. Like this:

for (i = 0; i < nrapps; i++) {			
   var appnr = document.Form1.elements['txtAppNr' + id].value;
   var floor = document.Form1.elements['txtFloor' + id].value;
   var unitplac = document.Form1.elements['txtUnitPlac' + id].value;
   var consid = document.Form1.elements['txtConsID' + id].value;
   var unitnr = document.Form1.elements['txtUnitNr' + id].value;
   var unitset = document.Form1.elements['txtUnitSet' + id].value;
   var fuse = document.Form1.elements['txtFuse' + id].value;
   var customer = document.Form1.elements['txtCustomer' + id].value;
   var dob = document.Form1.elements['txtDOB' + id].value;
   <ajaxcode>.CB_Function(regid,appnr,floor,unitplac,consid,unitnr,unitset,fuse,customer,dob,ServerSide_Callback2);
   if (On_Error == true) { return; }
   id++;
}

So my thought was to store the information in a 2D-array and then pass that array to the ajax-function in order to let that function in turn store the information to the db …

Oxiegen 88 Basically an Occasional Poster Featured Poster

Well. FireFox showed a few errors, like "error in string" (or something like that).
But when I added a check for browser type to solve the DOM differences between IE and FF, the errors vanished.

Before:

var appTable = document.getElementById("appTable");
var a = document.createElement('<div id="a' + appInc + '">');
appTable.appendChild(a);

After:

var appTable = document.getElementById("appTable");
if (navigator.appName == "Microsoft Internet Explorer") {
            var a = document.createElement('<div id="a' + appInc + '">');
} else {
            var a = document.createElement('div');
            a.setAttribute("id", "a" + appInc);
}
appTable.appendChild(a);

Whatever I did. This now works on localhost without errors. Weirdness.
So I suppose that this issue is resolved. I guess. Unless anyone has something to add that explains this?

Oxiegen 88 Basically an Occasional Poster Featured Poster

Actually, I don't. I'm using IE6.
And it's not the security popup.
What I get is the yellow triangle with a black exclamationpoint, in the statusbar of the browser, stating that this-or-that is undefined.

Oxiegen 88 Basically an Occasional Poster Featured Poster

Hi!

I don't know if this has been answered already and a search gave to many results.

I have a website that is built with ASP.NET and that uses some javascript.
When I run a debug on localhost to check for errors the ASP.NET code works just fine, but every single piece of javascript code generates some kind of error on a OnClick event.

The specifik error is not important. What is important is that it is an error.
When I publish to a dedicated webserver the javascript does yields no errors what so ever.

I have done a few google searches and the few hits that I got with this problem gave no answers, just a few lame excuses that the security settings may be to high or something like it.

Now, I have tried this with a very low setting with the same result.
So. What's the difference, besides this being localhost, between a webserver on localhost and a webserver on a server?
And why do I, and others, get a javascript error only on localhost?

I'm running IIS on both with identical configurations.

Oxiegen 88 Basically an Occasional Poster Featured Poster

Problem solved.
I simply added a funktion that returns the string containing the values.

By calling the funktion like this:

values = DataValues(row, dt.Columns.Count - 1)

The information is returned like this:

Private Function DataValues(ByVal DRow As DataRow, ByVal Max As Integer) As String
        Dim retVal As String

        retVal = "'" & DRow.Item(0) & "',"
        For i As Integer = 1 To Max - 1
            retVal &= "'" & DRow.Item(i) & "',"
        Next
        retVal &= "'" & DRow.Item(Max) & "'"

        Return retVal
    End Function
Oxiegen 88 Basically an Occasional Poster Featured Poster

Why not just extract the HTML part from the XML file, display it in a hidden WebBrowser control and then print it from there?

That would be the same as printing a normal webpage from, say Internet Explorer using
File->Print. Right?

Oxiegen 88 Basically an Occasional Poster Featured Poster

Hi!
Sorry about my bad grammer and/or spelling. English is not my native language.

I don't know if this already have been asked and answered, however...

I'm currently developing a program in which it will be possible to select table fields from a database and set various criteria using dropdown-lists. This will then dynamically generate an SQL-query string.
I then convert the datareader I use for this query into a datatable.

The above part works great.

Now to the problem.
I have other functions that perform an export to excel, but those has fixed number of fields and it's then easy, for example, to use VALUES ('" & row.Item(0) & "','" & row.Item(2) & "','" & row.Item(3) & "'..... to retrieve and export the information.

But because this latest function has fields that varies in number, the above code won't exactly work.
I need a way to retrieve the information into a single string where: str &= "'" & row.Item(<dynamic number 0 to field.count - 1>) & "'," .

And here's the crux. All this has to be performed inside a single For Each row AS DataRow In DataTable.Rows because the data is exported into excel row by row.

Any ideas?

Oxiegen 88 Basically an Occasional Poster Featured Poster

For buttons, take a look at the PerformClick() event.
Otherwise, have a look at the function Focus().

Oxiegen 88 Basically an Occasional Poster Featured Poster

Address book
ID3 tag editor
Inventory
Chat
FTP client
Image viewer
Calendar
Cook book

Oxiegen 88 Basically an Occasional Poster Featured Poster

Hi.

I'm having some difficulty here. Perhaps someone here has some ideas.

I would like to implement some kind of P2P functionality in an existing application that is designed to work within a local network.

The concept of this functionality is that the application stores the username of the current user and the ip-address of the computer he's on to a database.
On a specific form all currently logged on users that are using this application are listed from the database. And the idea is that from this form be able to send a short text message to another user.

I wanted to have a server part with a tcp-listener in a separate thread that's constantly running until application shutdown, and a client part that sends the message.

I almost had it going for a while, but the threaded server part never shut down when closing the app. :sad:

Any ideas of how to accomplish this kind of thing?

//Oxiegen

Oxiegen 88 Basically an Occasional Poster Featured Poster

Hi!

I've come across an interesting, and annoying, bug(?) in Visual Studio 2005.
I don't know if anyone else has been experiencing this bug, and I don't know if this is something that exists in all versions, but it does in mine. I'm using version 8.0.50727.42.

I have set the solution explorer to not show all files, only the vb files.
The thing that happens is that when you're dealing with a lot of forms, at one point something happens and one, or more, of the forms are split into separate files (designer, resource and form code).
Which leads to that when you double-click the vb file to see the designer an empty form is displayed. But when you right-click and choose View Code, all code is present and accounted for.

I haven't figured out why this happens, but for some reason two essential values are removed from the project file (in my case the .vbproj file).

The values in question are marked in red.

<Compile Include="form1.Designer.vb">
  <DependentUpon>form1.vb</DependentUpon>
    </Compile>

and

<EmbeddedResource Include="form1.resx">
        <SubType>Designer</SubType>
  <DependentUpon>form1.vb</DependentUpon>
    </EmbeddedResource>

My work-around for this bug is to manually reinsert these values with notepad, or some other texteditor, and reload the project.
And voila! Everything is back to normal again. :)

Oxiegen 88 Basically an Occasional Poster Featured Poster

I solved it myself using the dataview class.

Dim dbView As DataView
dbView = new DataView(DataSet1.Tables("<tablename>"))
dbView.Sort = "id DESC"
 
cmbRegID.DisplayMember = "column2"
cmbRegID.DataSource = dbView
cmbRegID.SelectedIndex = 0

Now everytime I add (or delete) items from the datatable it shows in the combox right away (and selects the latest added item).

Oxiegen 88 Basically an Occasional Poster Featured Poster

Hi, guys!

Got a problem here. :)

I have a form that when it loads spawns a thread which in turn fills a publicly declared dataset with a table by a dataadapter and then binds a field from the table to a combobox.

combobox1.DisplayMember = "fieldName"
combobox1.ValueMember = "fieldName"
combobox1.DataSource = dataset1.Tables("<tablename>")

This works like a charm.
I can fetch existing records and manipulate the data (edit and update) perfectly.

But this is the crux.
When I clear the form, add information and save it as a new record, everything is stored in the database as it should and I explicitly use the method dataset1.Tables("<tablename>").AcceptChanges after the update to the server.
However, the bound combobox is not updated with the new information.

I have the impression that if you add a record to a table that is bound to a control and force the update on the table, that information is immediatly available to the control.

I've been googling for an answer for three days without much luck.
My last attempt at this involved iterating through the table with for each row as dataset1.table("<tablename>").Rows . But that took too long and screwed up the thread.

Can you help me find a solution to this?

I connect to a MSSQL 2000 server and use untyped datasets, all by code.

Oxiegen 88 Basically an Occasional Poster Featured Poster

Hello!

Now I have another problem.

I have successfully implemented cross-page postback with ASP.NET 1.1 using:

Protected Sub submit_Click(ByVal sender As Object, ByVal e As System.EventArgs)
  For Each o As Object In Page.Request.Form
       Dim ctlName As String = o.ToString()
       If Not ctlName.StartsWith(UniqueID & ":") Then
             GoTo cont
       End If

       Dim parts() As String
       parts = Split(ctlName, ":")
           Context.Items(parts(parts.Length - 1)) = Page.Request.Form(ctlName)
cont:
  Next
  Page.Server.Transfer(action)
End Sub

However, i have several grouped radiobuttons. All in all, two groups.

The problem is that above subroutine only extracts the unique id of each rendered webcontrol (i.e. the name of the input field), not the ID of the control.
There is a snag during population of the form on the recieving page when using grouped radiobuttons, because the variable ctlName contains the name of the group, not the name of the control.

I have considered not grouping them, but that's not an option in this case.

I would like to extract and transfer the ID's instead of the names of the control.

Any ideas?

Oxiegen 88 Basically an Occasional Poster Featured Poster

Hi.

Try exchanging Label1.RenderControl(htmlTW) with Page.RenderControl(htmlTW) .
This will give you the entire page including all controls.

Or, you can put the code inside a <div> tag like this:

<div id="divPanel" runat="server">
<your code>
</div>

And then use divPanel.RenderControl(htmlTW) .

Oxiegen 88 Basically an Occasional Poster Featured Poster

I solved it myself by expanding the coding Sathiya used in this thread: http://www.daniweb.com/techtalkforums/showthread.php?t=45854

My solution was to use the RenderControl method in the Page class.
This gives me the entire entity of the rendered page as a string, which can then be used as body in a html-mail.
And this can be done without any hidden variables and javascript code.

Oxiegen 88 Basically an Occasional Poster Featured Poster

Hi, all!

I've been trying to pass a javascript variable to an asp.net webapp through a hidden input field.
All according to post http://www.daniweb.com/techtalkforums/thread26184.html.

But something seems to be garbled.

Here's what parts of my aspx code looks like.

...
             var src = document.documentElement.outerHTML;
                   document.getElementById("pSource").Value = src;
               }
 </script>
</head>
<body>
<form runat="server">
      <input id="pSource" type="hidden" />
...

Somehow the line document.getElementById("pSource").Value = src; doesn't work.
I've tried with <input id="pSource" type="hidden" runat="server" /> as well.

The javascript code is in a window.onload function.
What I want to do is to have the content of the hidden field mailed as html from CodeBehind.

Any suggestions?