C# and web programming

Associate
Joined
27 Jan 2005
Posts
1,397
Location
S. Yorks
First of all I am a newb with C# and if its even possible I am an even more newb with web programming.

Anyway I have written a c# app that connects to a backend SQL database, the app has three combo boxes, first one influences the second, first and second influence the third.

The user then enters a quantity and weight for a given type and then when the weight text box is left the system does a series of calcultaions before populating a datagrid with the results.

I now need to convert this to a web app, so using c# have created a new project, created the main form and all was going well until I went to try to add an onleave event to the textboxes. After much searching have found the onblur command but when I use this I get the following error message:

Microsoft JScript runtime error: 'calcPallets' is undefined

Now I presume I need to include some javascript to call the calPallets function which is in the wepage? How do I do this?

Other question is there a slicker way to populate the combo boxes / dropdown list boxes as I hate the flickering of the screen, presumably as it is waiting for the server to send the data back to the form?

One final question I am bemused by all of this, is there a better way of building a data driven website, or at least one that looks slicker?

Matt
 
PHP is very good at server side scripting to access and read/write to databases and also to handle forms.

Incorporating into standard html pages is easy as well. Quite a simple language, it would be my first choice for dynamic web pages.

andy
 
The best tutorial to learn .Net MVC is Nerd Dinner.

With regard to AJAX, personally I use jQuery's implementation as the .Net AJAX tools are a retarded abortion at best (yes I know they use jQuery underneath, but the configuration of them is a PITA that can be entirely avoided).
 
Sorry for not getting back to this thread, been trying to get my head around it reading many tutorials on the net and still none the wiser.

Stelly will create an msn account and message you later.

Matt
 
Right am taking two steps forward and three backwards at the moment, but am sticking with just converting windows app to asp, anyway I digress.

I need to create a modal popup, the popup should display a number of textboxes depending on a number contained within the main form, as each of these text boxes are left a calculation is performed and the results from this passed back to a gridview on the mainform.

Sounds easy in a windows app but...

Any ideas anyone?


Matt
 
For a modal window (or anything front-end) you'll need to use javascript, or the jQuery framework to make it a bit simpler.

Try jQueryUI, although there are many others which allow for more customisation and have less bloat.
 
Have modified the code to this on the modal form

Code:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="frmGetW.aspx.cs" Inherits="CC.frmGetW" %>

<!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>
    <script language="javascript">
        function Done() {
           
            window.close();
        }

        function doInit() {
            
            var ParmA = "Aparm";
            var MyArgs = new Array(ParmA);
            MyArgs = window.dialogArguments;
            changeIt(MyArgs[0].toString());            
        }

        function changeIt(astring)
        {
            for (i = 1; i <= astring; i++) 
            {
                my_div.innerHTML = my_div.innerHTML + "<br><input type='text' name='mytext'+ i>"
            }
        }

</script>
</head>
<BODY onload="doInit()">
<div id="my_div"></div>
<BUTTON onclick="Done()" type="button">OK</BUTTON>
</BODY>
</html>

Now how do I loop through all the dynamicly created text boxes, checking the values and erforming the calculation I need to do? Or how do I assign an event to the textboxes such as on blur?

Matt
 
Got this bit sorted now:

Code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="frmGetW.aspx.cs" Inherits="CCr.frmGetW" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Child Webform</TITLE>
<script language="javascript">
    function Done() {
        var ParmA = "Aparm";
        var MyArgs = new Array(ParmA);
        MyArgs = window.dialogArguments;

        var MyArgs2 = new Array();                      // set up array to hold values
        for (i = 1; i <= MyArgs[0].toString(); i++) {
            MyArgs2[i] = getValue(i);
        }                                               // Gets values and populates array
        window.close();
    }
    function getValue(astring) {                        // Returns value from textbox
        var txtValue = document.getElementById('mytext'+ astring).value;
        return txtValue
    }
    function doInit() {                                 // Called when form loads calls changeIt to generate required textboxes                   
        changeIt(window.dialogArguments);
    }
    function changeIt(astring) {                        // Generates textboxes on form
        for (i = 1; i <= astring; i++)
            {
                my_div.innerHTML = my_div.innerHTML + "<br><input type='text' id='mytext"+ i +"' value=0>"
            }
    }
</script>
</HEAD>
<BODY onload="doInit()">
<div id="my_div"></div>
<BUTTON onclick="Done()" type="button">OK</BUTTON>
</BODY>
</HTML>

Question is what do I do next?

I need to pass either individual values to a c# function to perform a calculation which returns a GridView, repeating this for all textboxes and adding results to the gridview and then display the gridview.

Any guidelines on how to do this?

Mat
 
Have worked out I need to create a hidden field on the main page, but how do I pass the array from the modal page to the hidden control on the main page?

Matt
 
Also is there a way to force a c# event to fire from javascript, e.g. once the hidden field has textchanged I want it to fire a c# event.

Matt
 
Was about to say "before someone suggests writing an xmlhttprequest, it would be much easier to just post 'no, it's not possible'"
 
Since this is webforms, then yes, it's possible.

1. Add [AjaxMethod] to the method
2. Add ScriptManager to the page
3. Register the class with the AjaxMethod to the ScriptManager

And you get a javascript stub for your class on the page.

Might want to look into some lighter weight API's for ajax, jQuery and the likes...
 
Back
Top Bottom