枫中稻草
想要的话,就去争取

在Reapter数据绑定时,对Reapter中控件的操作  

protected void RepInfo_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
  
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
  //要操作的控件所在位置Item或AlternatingItem
  {

    HyperLink hlTitle
= (HyperLink)e.Item.FindControl("hlTitle"); //获取控件

if (hlTitle.Text.Length > 16) //判断控件文本的长度

  hlTitle.Text
= hlTitle.Text.Substring(0, 16) + "...";
  }
}

 

 后台添加HTML标记语言(需要转化)   

/// <summary>
/// 替换html中的特殊字符
///
</summary>
///
<param name="theString">需要进行替换的文本</param>
///
<returns>替换完的文本</returns>
public static string HtmlEncode(string theString)
{
theString = theString.Replace(">", "
&gt;");
theString = theString.Replace("
<", "&lt;");
theString
= theString.Replace(" ", "&nbsp;");
theString
= theString.Replace(" ", "&nbsp;");
theString
= theString.Replace("\"", "&quot;");
theString
= theString.Replace("\'", "'");
theString
= theString.Replace("\n", "<br/> ");
return theString;
}

///
<summary>
/// 恢复html中的特殊字符
///
</summary>
///
<param name="theString">需要恢复的文本</param>
///
<returns>恢复好的文本</returns>
public static string HtmlDecode(string theString)
{
theString = theString.Replace("
&gt;", ">");
theString = theString.Replace("
&lt;", "<");
theString
= theString.Replace("&nbsp;", " ");
theString
= theString.Replace("&nbsp;", " ");
theString
= theString.Replace("&quot;", "\"");
theString
= theString.Replace("'", "\'");
theString
= theString.Replace("<br/> ", "\n");
return theString;
}

  

字符串编写  

  1.  @符号的用法

         在写大段的客户端脚本时,可以在文本前加入@,这样,引起来的字符器的换码序列将被处理,

   这样就可以轻松写出字符串。如果要在字符器里包括一个双引号,请使用两对双引号。    

  2.  在字符串中添加参数

String sql_infomation = @"update {0} set information_type_id = '{1}', information_title = '{2}',
release_person = '{3}', information_content = '{4}' ";
sql_infomation = string.Format(sql_infomation,
table_name, Convert.ToInt32(ddlInfoType.SelectedValue),tbTitle.Text,
Convert.ToInt32(ddlAuthor.SelectedValue));

 

 后台调用前台JavaScript

Respose.write(str);
Page. RegisterClientScriptBlock ("", str);
Page.RegisterStartupScript("", str);
关于ajax中UpdatePanel中javascript中(alert)弹出消息框的问题
ScriptManager.RegisterClientScriptBlock(UpdatePanel1,typeof(UpdatePanel),
                        "test", "alert('保存成功!');", true);

    RegisterClientScriptBlockRegisterStartupScript

  这两个方法都接受两个字符串作为输入。第一个参数 key 是插入的客户端脚本的唯一标识符。

  第二个参数 script 是要插入到页面中的客户端脚本,包括<script> 的起始标记和终止标记。

   Response.Write输出后的位置在源文件的第一行.

  RegisterClientScriptBlock输出后的位置会在<form>的下一行.(asp.net自带的脚本和一些隐藏域之下).

  RegisterStartupScript输出后的位置会在</form>的上一行.

 

Ajax日历控件------CalendarExtender中文本地化

CalendarExtender日历默认是英文,如需要中文本地化支持,只需在<asp:ScriptManager/>中增加
EnableScriptGlobalization="true"
EnableScriptLocalization="true"
两个属性即可

 

posted on 2010-03-18 20:01  枫中稻草  阅读(563)  评论(0编辑  收藏  举报