protected void btnHighLight_Click(object sender, EventArgs e) { string _error = string.Empty; // Check the value of user's input data. if (CheckControlValue(this.ddlLanguage.SelectedValue, this.tbCode.Text, out _error)) { // Initialize the Hashtable variable which used to // store the different languages of code and their // related regular expressions with matching options. Hashtable _htb = CodeManager.Init(); // Initialize the suitable collection object. RegExp _rg = new RegExp(); _rg = (RegExp)_htb[this.ddlLanguage.SelectedValue]; this.lbResult.Visible = true; if (this.ddlLanguage.SelectedValue != "html") { // Display the highlighted code in a label control. this.lbResult.Text = CodeManager.Encode( CodeManager.HighlightCode( Server.HtmlEncode(this.tbCode.Text) .Replace(""", "\""), this.ddlLanguage.SelectedValue, _rg) ); } else { // Display the highlighted code in a label control. this.lbResult.Text = CodeManager.Encode( CodeManager.HighlightHTMLCode(this.tbCode.Text, _htb) ); } } else { this.lbError.Visible = true; this.lbError.Text = _error; } }
protected void btnHighLight_Click(object sender, EventArgs e) { string _error = string.Empty; // 检查用户输入的数据. if (CheckControlValue(this.ddlLanguage.SelectedValue, this.tbCode.Text, out _error)) { // 初始化根据匹配选项用来保存不同语言代码 // 及其相关正则表达式的散列表变量. Hashtable _htb = CodeManager.Init(); // 初始化合适的集合对象. RegExp _rg = new RegExp(); _rg = (RegExp)_htb[this.ddlLanguage.SelectedValue]; this.lbResult.Visible = true; if (this.ddlLanguage.SelectedValue != "html") { // 在标签控件中显示高亮的代码. this.lbResult.Text = CodeManager.Encode( CodeManager.HighlightCode( Server.HtmlEncode(this.tbCode.Text) .Replace(""", "\""), this.ddlLanguage.SelectedValue, _rg) ); } else { // 在标签控件中显示高亮的代码. this.lbResult.Text = CodeManager.Encode( CodeManager.HighlightHTMLCode(this.tbCode.Text, _htb) ); } } else { this.lbError.Visible = true; this.lbError.Text = _error; } }