Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Request.Form issue

Status
Not open for further replies.

kyern

Programmer
Mar 30, 2006
36
US
I have a weird problem that should have been very easy. I have a form with a lot of entries. When I try to pull a value after post back I get a NullRef. I turned tracing on and it shows that they are there, it shows the value I am expecting, but for some reason I cant retrive it. The code is long so I have shortened it. Any help is very appreciated.

David

Code:
<%@ Page Language="C#" Trace="true" %>
<script Language="C#" runat="server">
	public PHP.OrderedMap pckarr = new PHP.OrderedMap();
	public string qry;
	public System.Data.DataTable rlt;
	public PHP.OrderedMap row;
	public System.Data.Odbc.OdbcConnection MyConnection = new System.Data.Odbc.OdbcConnection("DSN=###");
	public double pcount = 0;

	protected void Page_Load(Object Source, EventArgs E) 
 	{ 
   		if (IsPostBack) 
		{ 
  			Response.Write("Table Updated<BR>");
            	update_table("Video");
			update_table("HSD");
			update_table("Phone");
		} 
	} 

	public void update_table(string type)
	{
		string check = "";
		MyConnection.Open();
		pckarr.Clear();
		qry = "SELECT * FROM packages WHERE status = 'active' AND (dept = 'disco' || dept = '" + type + "') ORDER BY level";
        	rlt = PHP.MySQLSupport.Query(qry, MyConnection);
		while(PHP.TypeSupport.ToBoolean(row=PHP.MySQLSupport.FetchArray(rlt, 0)))
		{
            	pckarr[row["package"].ToString()] = 0;
		}
		
		foreach (string package in pckarr)
		{
			foreach (string packageb in pckarr)
			{
				foreach (string packagec in pckarr)
				{
					string formName = package + packageb + packagec;
					if (Request.Form.[formName] != String.Empty) 
					{
						string val = Request.Form[formName].ToString();
						Response.Write(val);						

					}
				}
			}
		}
	MyConnection.Close();
	}

	public void draw_grid()
	{
		MyConnection.Open();
        	string cqry;
        	System.Data.DataTable crlt;
        	PHP.OrderedMap crow;
        	int count;
		type = "Phone";
		Response.Write("<font size=3><BR><B>Phone</B><BR>");
		pckarr.Clear();
		qry = "SELECT COUNT(id) AS count FROM packages WHERE status = 'active' AND (dept = 'disco' || dept = '" + type + "')";
        	rlt = PHP.MySQLSupport.Query(qry, MyConnection);
		row=PHP.MySQLSupport.FetchArray(rlt, 0);
		pcount = PHP.TypeSupport.ToInt32(row["count"].ToString());
        	qry = "SELECT * FROM packages WHERE status = 'active' AND (dept = 'disco' || dept = '" + type + "') ORDER BY level";
        	rlt = PHP.MySQLSupport.Query(qry, MyConnection);
        	while(PHP.TypeSupport.ToBoolean(row=PHP.MySQLSupport.FetchArray(rlt, 0)))
        	{
        	    pckarr[row["package"].ToString()] = 0;
        	}

        	Response.Write("<table>");
        	Response.Write("<tr><td>TO &rArr </td>");

			
        	foreach (string package in pckarr)
        	{
			Response.Write("<td colspan = \"" + pcount + "\">" + package + "</td>");
       		 }
		Response.Write("<tr><td>WANT &rArr </td>");
		for(int i = 0; i < pcount; i++)
		{
			foreach (string package in pckarr)
			{
				Response.Write("<td>" + package + "</td>");
			}
		}
        	Response.Write("</tr><tr><td>FROM &dArr </td>");
        	foreach (string package in pckarr)
        	{
			foreach (string packageb in pckarr)
			{
				Response.Write("<td>&nbsp;</td>");
			}
		}
        	Response.Write("</tr>");
        	foreach (string package in pckarr)
        	{
			if(package != "Disconnect")
			{
           	 Response.Write("<tr><td>" + package + "</td>");
           	 foreach (string packageb in pckarr)
           	 {
				foreach (string packagec in pckarr)
				{
					cqry = "SELECT commission FROM savcmssn, packages a, packages b, packages c WHERE start = a.id AND a.package = '" + package + "' AND want = b.id AND b.package = '" + packagec + "' AND end = c.id AND c.package = '" + packageb + "'";
					crlt = PHP.MySQLSupport.Query(cqry, MyConnection);
					if(crlt.Rows.Count > 0)
					{
						crow = PHP.MySQLSupport.FetchArray(crlt, 0);
						Response.Write("<td><input type=\"text\" size=\"1\" name=\"" + package + packageb + packagec + " \" value=\"" + crow["commission"].ToString() + "\"></td>");
					}else
					{
						Response.Write("<td><input type=\"text\" size=\"1\" name=\"" + package + packageb + packagec + "\" value=&nbsp></td>");
					}
				}
            	}
            	Response.Write("</tr>");
			}
		}
		Response.Write("</tr><tr><td colspan=\"200%\"><input type=\"submit\" value=\"Submit\"></td></tr>");
		Response.Write("</table>");
		MyConnection.Close();
    	}	

</script>
<html>
    <head>
    <link rel="stylesheet" href="../../css/default.css" type="text/css">
    </head>
    <body>
		
        <%Functions.MyFunctions.do_login("commission_matrix.aspx");%>
		<form method="post" runat="server">
		<%
        		draw_grid();
		%>
		</form>
    </body>
</html>
 
In update_table this line:

string val = Request.Form[formName].ToString();
Response.Write(val);

Every way I've thought of to use Request.Form results in a NullRef
 
you don't need request.form.. just use Me.ControlName to access the control on the form
 
That wont work for me though becuase I have to construct the name dynamcially. Also when I try to use the Me keyword I get: The type or namespace name 'Me' could not be found (are you missing a using directive or an assembly reference?)
 
Am I missing a reference that I need or something? Its very weird that the values show up in the trace but I can't access them.
 
That wont work for me though becuase I have to construct the name dynamcially.
Then what you should be doing is creating a new control and adding it to somewhere (i.e. a Placeholder). Then, when the controls are created on each page load, you can simply use FindControl to get a reference to the control.

Also, what's with all the Response.Write statements and outdated HTML such as font tags? Do you realise the first will almost certainly create problems for you and the second is just very old and slower than newer methods?


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top