Kalaivani Kalai

Kalaivani Kalai

  • NA
  • 10
  • 438

array out of bounds exception in custom web server control.

Jan 28 2018 11:23 AM
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace SPLITTEXTCONTROL
{
[DefaultProperty("Text")]
[ToolboxData("<{0}:splittext runat=server></{0}:splittext>")]
public class splittext : WebControl
{
[Bindable(true)]
[Category("Appearance")]
[DefaultValue("")]
[Localizable(true)]
private TextBox _firstnametext = new TextBox();
private TextBox _lastnametext = new TextBox();
public string Text
{
get
{
String Text = _firstnametext.Text + _lastnametext.Text;
return ((Text == null) ? "[" + this.ID + "]" : Text);
}
set
{
ViewState["Text"] = value;
}
}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
_firstnametext.MaxLength = 10;
_lastnametext.MaxLength = 10;
_firstnametext.Width = new Unit("40px");
_lastnametext.Width = new Unit("40px");
}
protected override void RenderContents(HtmlTextWriter output)
{
String str = this.Text;
char[] delimiters = new char[] { ' ', ',' };
string[] parts = str.Split(delimiters);
_firstnametext.Text = parts[0];
_lastnametext.Text = parts[1];
_firstnametext.RenderControl(output);
_lastnametext.RenderControl(output);
}
}
}
 
what is wrong with my code when i try to create a web server control that parses the seperator for firstname and lastname.please give me a solution to solve this
 
 

Answers (1)