Ok, I posted in the bug forum, but I think that was not correct because I am sure the problem is probably me and not mojoPortal.
here is what I am attempting to do. I want to create a ServerControl webpart that has a label, a text box and a button. This is used to do a database search and just write the results as an HTML table on the page.
So far, I can get the control to do everything I want, except that the text in the textbox is completely ignored. No matter what I do, I cannot effect the results returned.
I have checked the SQL code, and I am sure it works (its very simple).
here is the source code of my webpart. Ive been trying for a few days, so there is a bit of slop in there..
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using MySql.Data;
namespace MyWebParts
{
public class RecallSearch : WebPart
{
Label lblLabel;
TextBox txtClaimNumber;
Button btnSearch;
private string strSearch = "";
public RecallSearch()
{
this.Title = "Recall Search";
this.Description = "Recall Search";
}
protected override void CreateChildControls()
{
lblLabel = new Label();
txtClaimNumber = new TextBox();
btnSearch = new Button();
lblLabel.Width = 100;
lblLabel.Text = "Claim Number: ";
this.Controls.Add(lblLabel);
txtClaimNumber.Text = "";
this.Controls.Add(txtClaimNumber);
btnSearch.Text = "Search";
this.Controls.Add(btnSearch);
if (Page.IsPostBack)
{
btnSearch.Text = "Search again";
this.strSearch = this.txtClaimNumber.Text;
}
this.ChildControlsCreated = true;
//base.CreateChildControls();
}
protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
EnsureChildControls();
//lblLabel.RenderControl(writer);
//txtClaimNumber.RenderControl(writer);
//btnSearch.RenderControl(writer);
Controls[0].RenderControl(writer);
Controls[1].RenderControl(writer);
Controls[2].RenderControl(writer);
if (Page.IsPostBack)
{
string cnnstr = "server=server;user id=user;database=database;
MySql.Data.MySqlClient.MySqlConnection MyCnn = new MySql.Data.MySqlClient.MySqlConnection();
MyCnn.ConnectionString = cnnstr;
if (MyCnn.State != System.Data.ConnectionState.Open)
{
MyCnn.Open();
}
MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand();
cmd.Connection = MyCnn;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "SELECT * FROM tblcontents WHERE txtClaimNumber like '" + this.strSearch +"%'";
MySql.Data.MySqlClient.MySqlDataReader reader;
reader = cmd.ExecuteReader();
writer.Write("<table>");
writer.Write("<tr><td>ID</td><td>Claim Number</td><td>Insured</td></tr>");
while (reader.Read())
{
writer.Write("<tr>");
writer.Write("<td>" + reader[0].ToString() + "</td>");
writer.Write("<td>" + reader["txtClaimNumber"].ToString() + "</td>");
writer.Write("<td>" + reader["txtInsured"].ToString() + "</td>");
writer.Write("</tr>");
}
writer.Write("</table>");
}
//base.Render(writer);
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
}
public override EditorPartCollection CreateEditorParts()
{
EditorPartCollection editorParts = base.CreateEditorParts();
return editorParts;
}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
}
public override WebPartVerbCollection Verbs
{
get
{
return base.Verbs;
}
}
}