How can I write value of parameter from webpage to EMX?

@ LouisCpro -

thank you for your suggestion, I am trying it.

sorry, I still can’t get the content of form.

I set a simple form in the Parameter_Field.html and I send two form-contents to johnsmith.html page with method “post”.


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>

<head>
<title>Form Test</title>
</head>

<body>
<form action="johnsmith.html" method="post">
  <p>First name: <input type="text" name="fname" /></p>
  <p>Last name:  <input type="text" name="lname" /></p>
  <input type="submit" value="Submit" />
</form>
</body>
</html>

After running webserve, typing “Fist name” and “Last name” and clicking submit button, the content is be sent to johnsmith.htmlpage principally. right?

The next step is to extract the content from the page " johnsmith.html".

I tried anything possible in the handler function, but not successful, I don’t know how to get the form-content from johnsmith.html.


        private static void Johnsmith(object sender, HttpServer.EventCallbackEventArgs e)
        {
           
            value1 = e.Post.Values.ToString();
            ??....??

            e.Response = Resources.GetString(Resources.StringResources.johnsmith);
            e.ResponseContentType = "text/html";
        }

@ Architect -
I tried many Hashtable method for the handler function. I can’t find the relation between key/value of Hashtable and the webpage johnsmith.html.

What about

e.Post[“fname”]

@ Architect -



       private static void Johnsmith(object sender, HttpServer.EventCallbackEventArgs e)
        {
            value1 = e.Post["fname"].ToString();
            e.Response = Resources.GetString(Resources.StringResources.johnsmith);
            e.ResponseContentType = "text/html";
        }


It works!!! I can get the content that I type in the form now !! thank you very much!!!

one question:

If I click the “submit” button after typing something in the form, the webpage will jump from one webpage to another webpage (from Parameter_Field.html to johnsmith.html).

I don’t want the “wegpage jumpping”, I want the webpag stay in Parameter_Field.html after clicking “submit” button, how can I do it?

You can use same Parameter_Field.html for both requests GET and POST. The e parameter will tell you what kind of request it is.

Or you can use AJAX and ignore the response.

I have two forms, and I want to post the contens of the two forms seperately. I want to get the corresponding content of form, if I click one submit button. I have tried manys times, but I can get only one content of form. why? the follow is my webpage codes:


in C# file

        private static void Johnsmith(object sender, HttpServer.EventCallbackEventArgs e)
        {
           value1 = e.Post["Parameter1"].ToString();
           value2 = e.Post["Parameter2"].ToString();
        }


<html>
<head>
<title>Form Post using AJAX</title>
<script type="text/javascript">

    var time_variable;

    function getXMLObject()  //XML OBJECT
    {
        var xmlHttp = false;
        try {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP")  // For Old Microsoft Browsers
        }
        catch (e) {
            try {
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP")  // For Microsoft IE 6.0+
            }
            catch (e2) {
                xmlHttp = false   // No Browser accepts the XMLHTTP Object then false
            }
        }
        if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
            xmlHttp = new XMLHttpRequest();        //For Mozilla, Opera Browsers
        }
        return xmlHttp;  // Mandatory Statement returning the ajax object created
    }

    var xmlhttp = new getXMLObject(); //xmlhttp holds the ajax object

    function ajaxFunction(ID) {
        var getdate = new Date();  //Used to prevent caching during ajax call
        if (xmlhttp) {
            var FormContent = document.getElementById(ID);
            xmlhttp.open("POST", "johnsmith.html", true); //calling testing.php using POST method
            xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
            xmlhttp.send(ID.toString() + "=" + FormContent.value); //Posting txtname to PHP File
        }
    }


</script>
</head>
<body>
  <form name="form1" action="">
  <td>Parameter 1.</td>
  <td><input type="text" name="Parameter_1" id="Parameter1" /></td>
  <td><input type="button" value="Submit1" onclick="ajaxFunction('Parameter1');" /></td>
  </form>

  <form name="form2" action="">
  <tr>
  <td>Parameter 2.</td>
  <td><input type="text" name="Parameter_2" id="Parameter2" /></td>
  <td><input type="button" value="Submit2" onclick="ajaxFunction('Parameter2');" /></td>
  </form>
</body>
</html>

I thought that, I get the value1 from1, if I click the “Submit1”. I get the value2 from2, if I click the “Submit2”. but I doesn’t work like what I think, and I can get only value1.
I can’t get value2 from form2.

How can I solve the problem?

@ andre.m -

Actually I have 1000 parameters, and I want to post the parameters seperately. Every parameter has a form and a submit button.

I don’t want to write 1000 times “function ajaxFunction(ID)” for every parameter. I want if I type a value in a form and click a submit button, the “onclick=” will call the “function ajaxFunction(ID)” with corresponding input-ID. The corresponding value will be sent to a webpage (johnsmith.html), and I will get the value in C# file.

I have tried many times my thinking just for sending 2 parameters from form1 and form2, but not successfull, you can see my webpage code and handler function in #52.

I don’t know why. In princip I have set everything like I think, but I can olny get value1 from form1, I can’t get the value2 from form2.

Can you give me some suggestion?

Have you inspected the EventCallbackEventArgs object, to see what data is actually in there? That’s the first thing I would peer deeper into. Set a breakpoint and hunt around and explain what you see.

@ workhard10 - if i see this “Actually I have 1000 parameters,” i think you have to change the approach and maybe your complete concept.
I also must say i did NOT read the complete thread so i don’t know where this is coming from or what you want to achieve.

how can I get the “key” of hashtable?

I have tried e.Post.Keys.Tostring(); but it doesn’t work.

@ Brett -

thank you! I will try it.

@ David@ Emrol -

yes, maybe you are right, I am also not very sure, whether the approach is right. I always try it and find the right way. At beginning I will define only 10 parameter to try, whether they work well.

not successfull… I can’t go on…so I want to repeat my refuse/problem.

I want to send 2 paramter from form to C# file. something like, if I click button “Submit1”, I will get the value of parameter1. if I click button “Submit2”, I will get the value of parameter2. (see picture)

I have tried it for a long time, but not successful. I can controll only one value of the parameter, I can’t controll the 2 forms/parameters like above what I want.

Is it possible the “key” of hashtable to get, if I click a button? I want to get/know the key, so that I know which button is clicked and decide which value to receive.

After trying many times, I really don’t know how to realize my thinking. Can you help me? or please give me some suggestion. thank you°!

the Parameter_Field.html is as follow, I have used AJAX methed to submit the form.


<html>
<head>
<title>Form Post using AJAX</title>
<script type="text/javascript">

    var time_variable;

    function getXMLObject()  //XML OBJECT
    {
        var xmlHttp = false;
        try {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP")  // For Old Microsoft Browsers
        }
        catch (e) {
            try {
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP")  // For Microsoft IE 6.0+
            }
            catch (e2) {
                xmlHttp = false   // No Browser accepts the XMLHTTP Object then false
            }
        }
        if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
            xmlHttp = new XMLHttpRequest();        //For Mozilla, Opera Browsers
        }
        return xmlHttp;  // Mandatory Statement returning the ajax object created
    }

    var xmlhttp = new getXMLObject(); //xmlhttp holds the ajax object

    function ajaxFunction(ID) {
        var getdate = new Date();  //Used to prevent caching during ajax call
        if (xmlhttp) {
            var FormContent = document.getElementById(ID);
            xmlhttp.open("POST", "johnsmith.html", true); //calling testing.php using POST method
            //xmlhttp.onreadystatechange = handleServerResponse;
            xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
            xmlhttp.send(ID.toString() + "=" + FormContent.value); //Posting txtname to PHP File
        }
    }

    function handleServerResponse() {
        if (xmlhttp.readyState == 4) {
            if (xmlhttp.status == 200) {
                //document.getElementById("message").innerHTML = xmlhttp.responseText; //Update the HTML Form element 
            }
            else {
                //alert("Error during AJAX call. Please try again");
            }
        }
    }
</script>
</head>

<body>
<form name="Parameter_1_form" action="">
Parameter 1.
<input type="text" name="Parameter_1" id="Parameter1" />
<input type="button" value="Submit1" onclick="ajaxFunction('Parameter1');" />
<br>
Parameter 2.
<input type="text" name="Parameter_2" id="Parameter2" />
<input type="button" value="Submit2" onclick="ajaxFunction('Parameter2');" />
</form>

</body>
</html>

Check Hashtable.Keys property it is a collection of all available keys. You can enumerate it and check all your paramters.

@ Architect -

I have tried something about “Hashtable.Keys”. but successful…


        private static void Johnsmith(object sender, HttpServer.EventCallbackEventArgs e)
        {
            keyname = e.Post.Keys.ToString();
            if (keyname == "Parameter1") value1 = e.Post["Parameter1"].ToString();
            if (keyname == "Parameter2") value2 = e.Post["Parameter2"].ToString();
        }

I have debug above codes, after clicking button, the “keyname” is null.

I have also tried the Enumerating the hashtable keys, as follow, but I got nothing from Debug.Print(dentry.Key.ToString());


        private static void Johnsmith(object sender, HttpServer.EventCallbackEventArgs e)
        {
            IEnumerator denum = e.Post.GetEnumerator();
            DictionaryEntry dentry;

            while (denum.MoveNext())
            {
                dentry = (DictionaryEntry)denum.Current;
                Debug.Print(dentry.Key.ToString());
            }

            if (keyname == "Parameter1") value1 = e.Post["Parameter1"].ToString();
            if (keyname == "Parameter2") value2 = e.Post["Parameter2"].ToString();
        }

I don’t where is the wrong.

I have solved my problem, You are right! I should check the “Hashtable.Keys property”. thank you very much!

I can get the “key” of hashtable and to choose the “value” of hashtable for every form/button now.


        private static void Johnsmith(object sender, HttpServer.EventCallbackEventArgs e)
        {
            foreach (DictionaryEntry Getkey in e.Post)
            {
                Debug.Print("Key is " + Getkey.Key);
                keyname = Getkey.Key.ToString();
            }

            if (keyname == "Parameter1") value1 = e.Post["Parameter1"].ToString();
            if (keyname == "Parameter2") value2 = e.Post["Parameter2"].ToString();
        }