473,511 Members | 16,983 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Button event not firing

I have a Web User Control that parses an XML file and renders a Form
based on the XML.
The problem is that I create a button on the bottom of the form that
will fire off a subscribeable event, but somehow the button never seem
to fire that particular event.

The code is attached below.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml;

public partial class uc_XmlGui : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
this.FormSubmitted += new EventHandler(XmlGui_FormSubmitted);
}

void XmlGui_FormSubmitted(object sender, EventArgs e)
{
}

private XmlDocument m_xmlguidatasource;
private string m_targetform;
private string tableStyle;
private string headercolumnstyle;
private string datacolumnstyle;
private string tablefooterstyle;
private string tableheaderstyle;

/// <summary>
/// Event that fires when the generated form is submitted.
/// </summary>
public event EventHandler FormSubmitted;

/// <summary>
/// Datasource for GUI.s
/// </summary>
public XmlDocument GuiDataSource
{
get
{
return this.m_xmlguidatasource;
}
set
{
this.m_xmlguidatasource = value;
}
}

/// <summary>
/// Name of target form in datasource
/// </summary>
public string TargetForm
{
get
{
return this.m_targetform;
}
set
{
this.m_targetform = value;
}
}

/// <summary>
/// binds he datasource to the GUI
/// </summary>
public override void DataBind()
{
XmlElement e = m_xmlguidatasource.DocumentElement;
XmlNamespaceManager xnm = new
XmlNamespaceManager(m_xmlguidatasource.NameTable);
xnm.AddNamespace("a", "http://m2c.no/GuiSchematics.xsd");
// finding the proper Form definition
XmlNodeList nl = e.SelectNodes("/*/a:Form", xnm);
foreach (XmlNode _form in nl)
{
XmlElement form = _form as XmlElement;
if (form.GetAttribute("Name").Equals(m_targetform))
{
// We've got the right form!
// Now getting the styles
XmlNodeList styles = form.SelectNodes("a:Styles/*",
xnm);
foreach (XmlNode style in styles)
{
switch (style.Name)
{
case "TableStyle":
this.tableStyle = style.InnerText;
break;
case "TableHeaderStyle":
this.tableheaderstyle = style.InnerText;
break;
case "HeaderColumnStyle":
this.headercolumnstyle = style.InnerText;
break;
case "DataColumnStyle":
this.datacolumnstyle = style.InnerText;
break;
case "TableFooterStyle":
this.tablefooterstyle = style.InnerText;
break;
}
}
// done fetching the styles. now styling the table
style(this.tblDynamicTable, this.tableStyle);
// now fetching the rows
XmlNodeList rows = form.SelectNodes("a:Rows/*",
xnm);
foreach (XmlNode _row in rows)
{
XmlElement row = _row as XmlElement;
bool req =
bool.Parse(row.GetAttribute("Required"));
if (bool.Parse(row.GetAttribute("Visible")))
{
// Display the row element only if defined as
visible
// and fetch all columns
TableRow trow = new TableRow();
XmlNodeList columns =
row.SelectNodes("a:Column", xnm);
// Make sure that the RFV and regex validator
// are placed in their own row if a multiline
// is rendered.
bool multiline = false;
foreach (XmlNode _col in columns)
{
XmlElement col = _col as XmlElement;
TableCell cell = new TableCell();
Dictionary<string, objectcontrols = new
Dictionary<string, object>();
controls.Add("label", new Label());
controls.Add("checkbox", new CheckBox());
TextBox __tb = new TextBox();
__tb.TextMode = TextBoxMode.MultiLine;
controls.Add("multiline", __tb);
controls.Add("textbox", new TextBox());
Button b = new Button();
b.Click += new EventHandler(b_Click);
controls.Add("button", b);
if
(bool.Parse(col.GetAttribute("IsHeaderColumn")))
style(cell, this.headercolumnstyle);
else
style(cell, this.datacolumnstyle);
// Set the colspan property if needed
if
(col.GetAttribute("ColumnSpan").Equals(string.Empt y) == false)
cell.ColumnSpan =
int.Parse(col.GetAttribute("ColumnSpan"));
// configuring the column and adding to
cell.Controls
collection
switch
(col.SelectNodes("a:Column.ControlType", xnm)[0].InnerText.ToLower())
{
case "label":

(controls[col.SelectNodes("a:Column.ControlType", xnm)
[0].InnerText.ToLower()] as Label).Text =
col.SelectNodes("a:Column.Content", xnm)[0].InnerText;

(controls[col.SelectNodes("a:Column.ControlType", xnm)
[0].InnerText.ToLower()] as Label).ID =
col.SelectNodes("a:Column.ControlName", xnm)[0].InnerText;

(controls[col.SelectNodes("a:Column.ControlType", xnm)
[0].InnerText.ToLower()] as Label).ToolTip =
col.SelectNodes("a:Column.ToolTip", xnm)[0].InnerText;

cell.Controls.Add((controls[col.SelectNodes("a:Column.ControlType",
xnm)[0].InnerText.ToLower()] as Label));
break;
case "multiline":

(controls[col.SelectNodes("a:Column.ControlType", xnm)
[0].InnerText.ToLower()] as TextBox).Text =
col.SelectNodes("a:Column.Content", xnm)[0].InnerText;

(controls[col.SelectNodes("a:Column.ControlType", xnm)
[0].InnerText.ToLower()] as TextBox).ID =
col.SelectNodes("a:Column.ControlName", xnm)[0].InnerText;

(controls[col.SelectNodes("a:Column.ControlType", xnm)
[0].InnerText.ToLower()] as TextBox).Columns =
int.Parse(col.SelectNodes("a:Column.MultiLineCharW idth", xnm)
[0].InnerText);

(controls[col.SelectNodes("a:Column.ControlType", xnm)
[0].InnerText.ToLower()] as TextBox).Rows =
int.Parse(col.SelectNodes("a:Column.MultiLineRowHe ight", xnm)
[0].InnerText);

(controls[col.SelectNodes("a:Column.ControlType", xnm)
[0].InnerText.ToLower()] as TextBox).MaxLength =
int.Parse(col.SelectNodes("a:Column.MaxLength", xnm)[0].InnerText);

(controls[col.SelectNodes("a:Column.ControlType", xnm)
[0].InnerText.ToLower()] as TextBox).ToolTip =
col.SelectNodes("a:Column.ToolTip", xnm)[0].InnerText;

cell.Controls.Add((controls[col.SelectNodes("a:Column.ControlType",
xnm)[0].InnerText.ToLower()] as TextBox));
multiline = true;
break;
case "textbox":

(controls[col.SelectNodes("a:Column.ControlType", xnm)
[0].InnerText.ToLower()] as TextBox).Text =
col.SelectNodes("a:Column.Content", xnm)[0].InnerText;

(controls[col.SelectNodes("a:Column.ControlType", xnm)
[0].InnerText.ToLower()] as TextBox).ID =
col.SelectNodes("a:Column.ControlName", xnm)[0].InnerText;

(controls[col.SelectNodes("a:Column.ControlType", xnm)
[0].InnerText.ToLower()] as TextBox).MaxLength =
int.Parse(col.SelectNodes("a:Column.MaxLength", xnm)[0].InnerText);

(controls[col.SelectNodes("a:Column.ControlType", xnm)
[0].InnerText.ToLower()] as TextBox).ToolTip =
col.SelectNodes("a:Column.ToolTip", xnm)[0].InnerText;

cell.Controls.Add((controls[col.SelectNodes("a:Column.ControlType",
xnm)[0].InnerText.ToLower()] as TextBox));
break;
case "checkbox":

(controls[col.SelectNodes("a:Column.ControlType", xnm)
[0].InnerText.ToLower()] as CheckBox).Text =
col.SelectNodes("a:Column.Content", xnm)[0].InnerText;

(controls[col.SelectNodes("a:Column.ControlType", xnm)
[0].InnerText.ToLower()] as CheckBox).ID =
col.SelectNodes("a:Column.ControlName", xnm)[0].InnerText;

(controls[col.SelectNodes("a:Column.ControlType", xnm)
[0].InnerText.ToLower()] as CheckBox).ToolTip =
col.SelectNodes("a:Column.ToolTip", xnm)[0].InnerText;

cell.Controls.Add((controls[col.SelectNodes("a:Column.ControlType",
xnm)[0].InnerText.ToLower()] as CheckBox));
break;
case "button":

(controls[col.SelectNodes("a:Column.ControlType", xnm)
[0].InnerText.ToLower()] as Button).Text =
col.SelectNodes("a:Column.Content", xnm)[0].InnerText;

(controls[col.SelectNodes("a:Column.ControlType", xnm)
[0].InnerText.ToLower()] as Button).ID =
col.SelectNodes("a:Column.ControlName", xnm)[0].InnerText;

(controls[col.SelectNodes("a:Column.ControlType", xnm)
[0].InnerText.ToLower()] as Button).ToolTip =
col.SelectNodes("a:Column.ToolTip", xnm)[0].InnerText;

cell.Controls.Add((controls[col.SelectNodes("a:Column.ControlType",
xnm)[0].InnerText.ToLower()] as Button));
break;
}
// and to finish up, we add the datacell
to the table
trow.Cells.Add(cell);
}
// Add the Validators
// Starting off with the
requiredfieldvalidator
if (multiline)
{
tblDynamicTable.Rows.Add(trow);
trow = new TableRow();
trow.Cells.Add(new TableCell());

TableCell validatorCell = new TableCell();
validatorCell.ColumnSpan = 2;
if (req)
{
RequiredFieldValidator rfv = new
RequiredFieldValidator();
rfv.ControlToValidate =
row.GetAttribute("RequiredFieldName");
rfv.ErrorMessage =
row.GetAttribute("RequiredFieldValidatorErrorMessa ge");
validatorCell.Controls.Add(rfv);
}
// Adding eventual
RegularExpressionValidator
XmlElement validator =
row.SelectSingleNode("a:Validator", xnm) as XmlElement;
if (validator != null)
{
// using default regexes
if
(validator.GetAttribute("UseDefaultRegEx").Equals( bool.TrueString))
{
XmlNodeList regexes =
e.SelectNodes("a:RegEx", xnm);
foreach (XmlNode _regex in
regexes)
{
XmlElement regex = _regex as
XmlElement;
if
(regex.GetAttribute("ID").Equals(validator.GetAttr ibute("DefaultRegExIdentifier")))
{
RegularExpressionValidator
rev = new RegularExpressionValidator();
rev.ValidationExpression =
regex.GetAttribute("Expression");
rev.ControlToValidate =
validator.GetAttribute("ControlToValidate");
rev.ErrorMessage =
regex.GetAttribute("ErrorMessage");

validatorCell.Controls.Add(rev);
break;
}
}
}
// using custom regexes
else
{
RegularExpressionValidator rev =
new RegularExpressionValidator();
rev.ValidationExpression =
validator.GetAttribute("CustomRegEx");
rev.ErrorMessage =
validator.GetAttribute("ErrorMessage");
rev.ControlToValidate =
validator.GetAttribute("ControlToValidate");
validatorCell.Controls.Add(rev);
}
}
// At last adding the validatorcell to the
row and finishing up
trow.Cells.Add(validatorCell);
tblDynamicTable.Rows.Add(trow);
}
else
{
TableCell validatorCell = new TableCell();
if (req)
{
RequiredFieldValidator rfv = new
RequiredFieldValidator();
rfv.ControlToValidate =
row.GetAttribute("RequiredFieldName");
rfv.ErrorMessage =
row.GetAttribute("RequiredFieldValidatorErrorMessa ge");
validatorCell.Controls.Add(rfv);
}
// Adding eventual
RegularExpressionValidator
XmlElement validator =
row.SelectSingleNode("a:Validator", xnm) as XmlElement;
if (validator != null)
{
// using default regexes
if
(validator.GetAttribute("UseDefaultRegEx").Equals( bool.TrueString))
{
XmlNodeList regexes =
e.SelectNodes("a:RegEx", xnm);
foreach (XmlNode _regex in
regexes)
{
XmlElement regex = _regex as
XmlElement;
if
(regex.GetAttribute("ID").Equals(validator.GetAttr ibute("DefaultRegExIdentifier")))
{
RegularExpressionValidator
rev = new RegularExpressionValidator();
rev.ValidationExpression =
regex.GetAttribute("Expression");
rev.ControlToValidate =
validator.GetAttribute("ControlToValidate");
rev.ErrorMessage =
regex.GetAttribute("ErrorMessage");

validatorCell.Controls.Add(rev);
break;
}
}
}
// using custom regexes
else
{
RegularExpressionValidator rev =
new RegularExpressionValidator();
rev.ValidationExpression =
validator.GetAttribute("CustomRegEx");
rev.ErrorMessage =
validator.GetAttribute("ErrorMessage");
rev.ControlToValidate =
validator.GetAttribute("ControlToValidate");
validatorCell.Controls.Add(rev);
}
}
// At last adding the validatorcell to the
row and finishing up
trow.Cells.Add(validatorCell);
tblDynamicTable.Rows.Add(trow);
}
}
}
// now styling footer row

style(this.tblDynamicTable.Rows[this.tblDynamicTable.Rows.Count - 1],
this.tablefooterstyle);
// now styling header row
style(this.tblDynamicTable.Rows[0],
this.tableheaderstyle);
}
}
EnsureChildControls();
base.DataBind();
}

private void style(WebControl item, string Css)
{
string[] directives = Css.Replace(" ",
"").Split(";".ToCharArray());
for (int i = 0; i < directives.Length - 1; i++)
{
string[] kvpair = directives[i].Split(":".ToCharArray());
item.Style.Add(kvpair[0], kvpair[1]);
}
}

void b_Click(object sender, EventArgs e)
{
this.FormSubmitted.Invoke(sender, e);
}
}
Jun 2 '08 #1
1 1629
I've isolated the problem to be due to the validators.

How can I have validators with this, and -- provided the validators
don't trigger -- make sure that the form submit process continues so
the button click event actually triggers?

Jun 2 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
5426
by: tshad | last post by:
I posted this on the asp.net group, also. I wasn't sure whether this was an asp.net problem or a javascript problem. I have a page that was originally created from a program I found on the net...
0
1630
by: manu_srinivasa | last post by:
:( Here is my design, we have user control placed in a aspx page. within user control, i am having datalist, within datalist i am placing radio button. On click of radio button, i need to...
2
9835
by: ~~~ .NET Ed ~~~ | last post by:
I have a problem (don't we all?). I have a web form with multiple modules, some of these modules have an ASP.NET (server run) button. OK, now I have UserControlX which has one such button (say...
2
3789
by: Andy Sutorius via DotNetMonster.com | last post by:
Hi, I have a delete button in the item template of my datagrid, when I click it the function for the Insert button is executed instead of the delete button. When I step through in debug, the...
6
1771
by: murl | last post by:
I have built a Web Custom Control using c#, and it's pretty simple. A dropdownlist, and a button that once clicked will render different html. I tried attaching an event handler to the Click event...
5
1946
by: csgraham74 | last post by:
Hi guys, I posted regarding this issue the other day but i still dont have an answer to my problem. Basically i have imported asp.net pages from dreamweaver into visual studio. Ive added a...
8
2068
by: helpful sql | last post by:
Hi, I have 2 radio buttons on my Windows form control. The radio button's CheckedChanged event disables or enables other controls on the form based on the value of the Checked property. When the...
3
5488
by: Jay | last post by:
I am on the 2.0 framework and have run the c:\windows\microsoft.net \framework\v1.1.4322\aspnet_regiis.exe -c and had no success. About half of the buttons on my webforms are firing and the other...
3
21047
by: GauravGupta | last post by:
i want to know that is it posible to call button click event before page load event on post back.... please help me....
5
5856
by: Tony | last post by:
I am continuing to develop an Access 2007 application which was originally converted from Access 2003. In Access 2003 I was able to disable the Access Close button in the top righthand corner of...
0
7245
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7144
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7356
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7085
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7512
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5671
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4741
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3227
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3214
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.