服务器端url,form操作方法,js输出方法等封装
2012-10-29 13:58
253 查看
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.Security;
using System.Web.UI.WebControls;
namespace Test
{
/// <summary>
/// common utils
/// </summary>
public static class Utils
{
#region javascript extension
#region ScriptManager
public static void JSFormBlock(this Page page, string scriptText, string key = "",bool addScriptTags=false)
{
if (string.IsNullOrEmpty(key))
{
key = Guid.NewGuid().ToString();
}
ScriptManager.RegisterClientScriptBlock(page, page.GetType(), key, scriptText, addScriptTags);
}
public static void JSFormStart(this Page page, string scriptText, string key = "", bool addScriptTags = false)
{
if (string.IsNullOrEmpty(key))
{
key = Guid.NewGuid().ToString();
}
ScriptManager.RegisterStartupScript(page, page.GetType(), key, scriptText, addScriptTags);
}
public static void JSFormBlock(this UserControl ucl, string scriptText, string key = "", bool addScriptTags = false)
{
if (string.IsNullOrEmpty(key))
{
key = Guid.NewGuid().ToString();
}
ScriptManager.RegisterClientScriptBlock(ucl, ucl.GetType(), key, scriptText, addScriptTags);
}
public static void JSFormStart(this UserControl ucl, string scriptText, string key = "", bool addScriptTags = false)
{
if (string.IsNullOrEmpty(key))
{
key = Guid.NewGuid().ToString();
}
ScriptManager.RegisterStartupScript(ucl, ucl.GetType(), key, scriptText, addScriptTags);
}
#endregion
#region JSResponse
public static void JSResponseClearWriter(this Page page, string scriptText)
{
page.Response.Clear();
page.Response.Write(scriptText);
}
public static void JSResponseWriter(this Page page, string scriptText)
{
page.Response.Write(scriptText);
}
public static void JSResponseEndWriter(this Page page, string scriptText, bool needClear = true, bool endSession = false)
{
if (needClear == true)
{
page.Response.Clear();
}
page.Response.Write(scriptText);
if (endSession == true)
{
page.Session.Abandon();
}
}
#endregion
#endregion
#region Redirect
public static void RedirectURL(this Page page, string url, bool endResponse = true)
{
try
{
page.Response.Redirect(url, endResponse);
}
catch
{
}
}
public static void RedirectURL(this UserControl ucl, string url, bool endResponse = true)
{
try
{
ucl.Response.Redirect(url, endResponse);
}
catch
{
}
}
#endregion
#region QueryString RequestForm
public static string QueryURLKeyValue(this Page page, string key, string defaultValue ="")
{
return page.Request.QueryString[key].ToMyString(defaultValue);
}
public static string QueryFormKeyValue(this Page page, string key, string defaultValue = "")
{
return page.Request.Form[key].ToMyString(defaultValue);
}
public static string QueryUrlOrFormKeyValue(this Page page, string key, string defaultValue = "")
{
return (page.Request[key] ?? page.Request.Form[key]).ToMyString();
}
public static string QueryURLKeyValue(this UserControl ucl, string key, string defaultValue = "")
{
return ucl.Request.QueryString[key].ToMyString(defaultValue);
}
public static string QueryFormKeyValue(this UserControl ucl, string key, string defaultValue = "")
{
return ucl.Request.Form[key].ToMyString(defaultValue);
}
public static string QueryUrlOrFormKeyValue(this UserControl ucl, string key, string defaultValue = "")
{
return ucl.Request[key].ToMyString();
}
#endregion
}
}
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.Security;
using System.Web.UI.WebControls;
namespace Test
{
/// <summary>
/// common utils
/// </summary>
public static class Utils
{
#region javascript extension
#region ScriptManager
public static void JSFormBlock(this Page page, string scriptText, string key = "",bool addScriptTags=false)
{
if (string.IsNullOrEmpty(key))
{
key = Guid.NewGuid().ToString();
}
ScriptManager.RegisterClientScriptBlock(page, page.GetType(), key, scriptText, addScriptTags);
}
public static void JSFormStart(this Page page, string scriptText, string key = "", bool addScriptTags = false)
{
if (string.IsNullOrEmpty(key))
{
key = Guid.NewGuid().ToString();
}
ScriptManager.RegisterStartupScript(page, page.GetType(), key, scriptText, addScriptTags);
}
public static void JSFormBlock(this UserControl ucl, string scriptText, string key = "", bool addScriptTags = false)
{
if (string.IsNullOrEmpty(key))
{
key = Guid.NewGuid().ToString();
}
ScriptManager.RegisterClientScriptBlock(ucl, ucl.GetType(), key, scriptText, addScriptTags);
}
public static void JSFormStart(this UserControl ucl, string scriptText, string key = "", bool addScriptTags = false)
{
if (string.IsNullOrEmpty(key))
{
key = Guid.NewGuid().ToString();
}
ScriptManager.RegisterStartupScript(ucl, ucl.GetType(), key, scriptText, addScriptTags);
}
#endregion
#region JSResponse
public static void JSResponseClearWriter(this Page page, string scriptText)
{
page.Response.Clear();
page.Response.Write(scriptText);
}
public static void JSResponseWriter(this Page page, string scriptText)
{
page.Response.Write(scriptText);
}
public static void JSResponseEndWriter(this Page page, string scriptText, bool needClear = true, bool endSession = false)
{
if (needClear == true)
{
page.Response.Clear();
}
page.Response.Write(scriptText);
if (endSession == true)
{
page.Session.Abandon();
}
}
#endregion
#endregion
#region Redirect
public static void RedirectURL(this Page page, string url, bool endResponse = true)
{
try
{
page.Response.Redirect(url, endResponse);
}
catch
{
}
}
public static void RedirectURL(this UserControl ucl, string url, bool endResponse = true)
{
try
{
ucl.Response.Redirect(url, endResponse);
}
catch
{
}
}
#endregion
#region QueryString RequestForm
public static string QueryURLKeyValue(this Page page, string key, string defaultValue ="")
{
return page.Request.QueryString[key].ToMyString(defaultValue);
}
public static string QueryFormKeyValue(this Page page, string key, string defaultValue = "")
{
return page.Request.Form[key].ToMyString(defaultValue);
}
public static string QueryUrlOrFormKeyValue(this Page page, string key, string defaultValue = "")
{
return (page.Request[key] ?? page.Request.Form[key]).ToMyString();
}
public static string QueryURLKeyValue(this UserControl ucl, string key, string defaultValue = "")
{
return ucl.Request.QueryString[key].ToMyString(defaultValue);
}
public static string QueryFormKeyValue(this UserControl ucl, string key, string defaultValue = "")
{
return ucl.Request.Form[key].ToMyString(defaultValue);
}
public static string QueryUrlOrFormKeyValue(this UserControl ucl, string key, string defaultValue = "")
{
return ucl.Request[key].ToMyString();
}
#endregion
}
}
相关文章推荐
- js的form表单提交url传参数(包含+等特殊字符)的解决方法
- BASE64-客户端(js)加码-服务器端(c#)解码,URL传递“汉字参数”解决方法。
- js的form表单提交url传参数(包含+等特殊字符)的两种解决方法
- BASE64-客户端(js)加码-服务器端(c#)解码,URL传递“汉字参数”解决方法
- js获取url查询字符串封装方法
- 怎么用php post 数据到服务器端,封装的方法,只需要输入url 和 post 数据即可
- 检查和验证的js方法封装(手机,身份证,IPv4,IPv6、邮箱、URL等)
- BASE64-客户端(js)加码-服务器端(c#)解码,URL传递“汉字参数”解决方法
- javascript BASE64-客户端(js)加码-服务器端(c#)解码,URL传递“汉字参数”解决方法
- js的form表单提交url传参数(包含+等特殊字符)的解决方法
- js获取url参数值的方法封装
- BASE64-客户端(js)加码-服务器端(c#)解码,URL传递“汉字参数”解决方法。
- MVC从服务器端返回js到客户端的方法(总结)
- 如何封装JS和CSS文件为服务器端控件
- js封装getByClass (JS获取class的方法封装为一个函数)的API
- js中简易选项卡的实现(3种方法实现样式的封装)
- JS获取URL中参数值(QueryString)的4种方法分享
- JS调用form的方法submit直接提交form的时候,submit事件不响应解决办法
- Node.js模块封装及使用方法