问题描述
Hello Guys
我想在Clientbox控件中显示客户端名称。数据来自数据库。但我面临的问题是每当我编辑该客户名称时
例如假设默认名称是Rajesh但如果我编辑它像< rajesh>那么它会生成异常错误位置0处没有排。现在我的方案是我想在文本框中显示可编辑的客户端名称。那么我该如何执行这项任务呢。请帮忙。谢谢
好的,这是我的代码:
Hello Guys
I want to display Client name into Textbox control. The data is coming from database. But problem i am facing is that whenever i edit the that client name
For example Suppose default name is "Rajesh" but if i edit it like " < rajesh >", It generates an exception error "There is no Row At Position 0". Now my scenario is that i want to display the client name inside textbox which is editable. So how can i perform this task. Please help. Thanks
Ok here is my code :
<%@ Page Title="" Language="C#" MasterPageFile="~/include/master/home_page.master" AutoEventWireup="true" CodeFile="message.aspx.cs" Inherits="admin_smsmarketing_message" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolderHead" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolderBody" Runat="Server">
<script type="text/javascript">
function OpenPage() {
var sValue = document.getElementById('<%=txtMessageText.ClientID %>').value;
if (sValue == "") {
alert("Please Type Your Message.");
}
else {
var sUrl = "/admin/smsmarketing/sendmessage.aspx";
window.open(sUrl, '_top', '', '');
}
}
$(document).ready(function () {
CharCount();
$('#<%=txtMessageText.ClientID %>').keyup(function (e) {
CharCount();
});
function CharCount() {
var tbLength = $('#<%=txtMessageText.ClientID %>').val().length;
$('#<%=lblCharCount.ClientID %>').text("Total Character: " + tbLength);
}
});
</script>
<div id="mid_undr_wrapp">
<div style="height: 23px;">
</div>
<div id="socialpage_tab_wrapp">
<div id="Progressbar_wrapp">
<ul id="progress">
<li class="blue"><a href="/admin/">Dashboard → </a></li>
<li class="blue"><a href="/admin/smsmarketing/sms_schedule_list.aspx">SMS →</a></li>
<li class="orange disable-link"><a href="#">Message Body →</a></li>
<li> <a class="disable-link" href="#">Contact List →</a></li>
<li><a class="disable-link" href="#">Schedule →</a></li>
<li><a class="disable-link" href="#">Confirmation </a></li>
</ul>
</div>
<div id="pge_heading_txt">
Message Body
</div>
<div style="height: 28px;">
</div>
<div style="width:80%; margin:0 auto;">
<div>
<div style="width: 30%; float: left;">
<b class="field-caption">SMS Content</b>
<br />
<asp:Label ID="lblCharCount" CssClass="lblmsg" runat="server" />
<br />
<div class="scheduleemailnote">
One message can contain upto 160 characters otherwise multiple messages will be
sent.
</div>
</div>
<div style="width: 70%; float: left;">
<div>
<asp:TextBox ID="txtMessageText" runat="server" TextMode="MultiLine" Height="120px"
Width="400px"></asp:TextBox>
</div>
<asp:RequiredFieldValidator ID="rfvMessage" ControlToValidate="txtMessageText" Display="None" runat="server" ErrorMessage="Please Type Your Message." />
<asp:ValidationSummary ID="vs" ShowMessageBox="true" ShowSummary="false" runat="server" />
</div>
</div>
<div style="height: 17px;">
</div>
<div style="text-align: left;">
<asp:ImageButton ID="btnBack" runat="server" ImageUrl="~/images/back.png" CausesValidation="false" OnClick="btnBack_Click" />
<asp:ImageButton ID="imgContinue" runat="server" ImageUrl="/images/continue.png" OnClick="imgContinue_Click" />
<asp:ImageButton ID="btnSave" runat="server" ImageUrl="/images/save.png" OnClick="btnSave_Click" />
<asp:ImageButton ID="btnCancel" runat="server" ImageUrl="/images/cancel.png" CausesValidation="false" OnClick="btnCancel_Click" />
</div>
</div>
<div class="clear">
</div>
<div style="height: 143px;">
</div>
</div>
</div>
</asp:Content>
CS:
使用系统;
使用系统.Collections.Generic;
使用System.Linq;
使用System.Web;
使用System.Web.UI;
使用System.Web.UI.WebControls;
使用socialmediasms;
public partial class admin_smsmarketing_message:System.Web.UI.Page
{
private int m_iClientId = 0;
private int m_iScheduleId = 0;
private int m_iCampaignTypeId = 0;
private string m_sScheduleName = string.Empty;
private string m_sMessageText = string.Empty;
private bool m_bUpdate = false;
protected void Page_Load(object sender,EventArgs e)
{
m_iClientId = Sessioncl.GetLoggedInClientId ();
m_iCampaignTypeId = ClientCampaigncl.GetCampaignType(ClientCampaigncl.eCampaignType.SmsMarketing);
if(Request.QueryString [i]!= null)
{
m_bUpdate = true;
m_iScheduleId = Numericcl.GetIntValue(Request.QueryString [i]);
}
else
{
m_iScheduleId = Numericcl.GetIntValue(Sessioncl.GetSessionScheduleId());
}
if(!IsPostBack)
{
this.PopulateDetails();
this.ManageButton();
ViewState [Referrer] = Stringcl.GetValue(Request。 UrlReferrer);
}
}
protected void imgContinue_Click(object sender,ImageClickEventArgs e)
{
EmailSchedulecl oEmailSchedulecl = new EmailSchedulecl(m_iClientId,m_iScheduleId);
m_iScheduleId = oEmailSchedulecl.UpdateSchedule(m_iCampaignTypeId,m_iScheduleId,oEmailSchedulecl.ScheduleStatusTypeId,oEmailSchedulecl.ScheduleName ,Stringcl.GetValue(txtMessageText.Text));
Response.Redirect(/ admin / smsmarketing / sms_user_list.aspx);
}
protected void btnBack_Click(object sender,ImageClickEventArgs e)
{
Response.Redirect(/ a dmin / smsmarketing / sms_schedule_list.aspx);
}
protected void btnSave_Click(object sender,ImageClickEventArgs e)
{
EmailSchedulecl oEmailSchedulecl = new EmailSchedulecl(m_iClientId,m_iScheduleId);
m_iScheduleId = oEmailSchedulecl.UpdateSchedule(m_iCampaignTypeId,m_iScheduleId,oEmailSchedulecl.ScheduleStatusTypeId,oEmailSchedulecl.ScheduleName,Stringcl .GetValue(txtMessageText.Text));
if(Stringcl.GetValue(ViewState [Referrer])!= string.Empty)
{
Response.Redirect(Stringcl.GetValue(ViewState [Referrer]));
}
else
{
Response.Redirect(/ admin / smsmarketing /);
}
}
protected void btnCancel_Click(object sender,ImageClickEventArgs e)
{
if(Stringcl.GetValue(ViewState [Referrer])!= string.Empty)
{
Response.Redirect(Stringcl.GetValue(ViewState [Referrer]));
}
else
{
Response.Redirect(/ admin / smsmarketing /);
}
}
private void PopulateDetails()
{
Clientcl oClientcl = new Clientcl(m_iClientId);
if(m_iScheduleId> 0)
{
try
{
EmailSchedulecl oEmailSchedulecl = new EmailSchedulecl(m_iClientId, m_iScheduleId);
string client_details = oClientcl.FirstName + \" \" + oClientcl.LastName;
txtMessageText.Text = \"From :\" + client_details;
txtMessageText.Text += \"\n\n\" + \"For unsubscribing contact\";
}
catch (Exception ex)
{
Errorcl.HandleException(ex, true);
}
}
}
private void ManageButton()
{
if (m_bUpdate)
{
imgContinue.Visible = false;
btnBack.Visible = false;
btnSave.Visible = true;
btnCancel.Visible = true;
}
else
{
imgContinue.Visible = true;
btnB ack.Visible = true;
btnSave.Visible = false;
btnCancel.Visible = false;
}
}
}
CS:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using socialmediasms;
public partial class admin_smsmarketing_message : System.Web.UI.Page
{
private int m_iClientId = 0;
private int m_iScheduleId = 0;
private int m_iCampaignTypeId = 0;
private string m_sScheduleName = string.Empty;
private string m_sMessageText = string.Empty;
private bool m_bUpdate = false;
protected void Page_Load(object sender, EventArgs e)
{
m_iClientId = Sessioncl.GetLoggedInClientId();
m_iCampaignTypeId = ClientCampaigncl.GetCampaignType(ClientCampaigncl.eCampaignType.SmsMarketing);
if (Request.QueryString["i"] != null)
{
m_bUpdate = true;
m_iScheduleId = Numericcl.GetIntValue(Request.QueryString["i"]);
}
else
{
m_iScheduleId = Numericcl.GetIntValue(Sessioncl.GetSessionScheduleId());
}
if (!IsPostBack)
{
this.PopulateDetails();
this.ManageButton();
ViewState["Referrer"] = Stringcl.GetValue(Request.UrlReferrer);
}
}
protected void imgContinue_Click(object sender, ImageClickEventArgs e)
{
EmailSchedulecl oEmailSchedulecl = new EmailSchedulecl(m_iClientId, m_iScheduleId);
m_iScheduleId = oEmailSchedulecl.UpdateSchedule(m_iCampaignTypeId, m_iScheduleId, oEmailSchedulecl.ScheduleStatusTypeId, oEmailSchedulecl.ScheduleName, Stringcl.GetValue(txtMessageText.Text));
Response.Redirect("/admin/smsmarketing/sms_user_list.aspx");
}
protected void btnBack_Click(object sender, ImageClickEventArgs e)
{
Response.Redirect("/admin/smsmarketing/sms_schedule_list.aspx");
}
protected void btnSave_Click(object sender, ImageClickEventArgs e)
{
EmailSchedulecl oEmailSchedulecl = new EmailSchedulecl(m_iClientId, m_iScheduleId);
m_iScheduleId = oEmailSchedulecl.UpdateSchedule(m_iCampaignTypeId, m_iScheduleId, oEmailSchedulecl.ScheduleStatusTypeId, oEmailSchedulecl.ScheduleName, Stringcl.GetValue(txtMessageText.Text));
if (Stringcl.GetValue(ViewState["Referrer"]) != string.Empty)
{
Response.Redirect(Stringcl.GetValue(ViewState["Referrer"]));
}
else
{
Response.Redirect("/admin/smsmarketing/");
}
}
protected void btnCancel_Click(object sender, ImageClickEventArgs e)
{
if (Stringcl.GetValue(ViewState["Referrer"]) != string.Empty)
{
Response.Redirect(Stringcl.GetValue(ViewState["Referrer"]));
}
else
{
Response.Redirect("/admin/smsmarketing/");
}
}
private void PopulateDetails()
{
Clientcl oClientcl = new Clientcl(m_iClientId);
if (m_iScheduleId > 0)
{
try
{
EmailSchedulecl oEmailSchedulecl = new EmailSchedulecl(m_iClientId, m_iScheduleId);
string client_details = oClientcl.FirstName + " " + oClientcl.LastName;
txtMessageText.Text = "From :" + client_details;
txtMessageText.Text += "\n\n" + "For unsubscribing contact";
}
catch (Exception ex)
{
Errorcl.HandleException(ex, true);
}
}
}
private void ManageButton()
{
if (m_bUpdate)
{
imgContinue.Visible = false;
btnBack.Visible = false;
btnSave.Visible = true;
btnCancel.Visible = true;
}
else
{
imgContinue.Visible = true;
btnBack.Visible = true;
btnSave.Visible = false;
btnCancel.Visible = false;
}
}
}
推荐答案
这篇关于在Textbox控件中输入用户名生成异常错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!