Asp. NET micro-credit user Group Management Web page _ Practical Tips

Source: Internet
Author: User
Tags datetime eval openid trim

The example of this article for everyone to share the ASP.net micro-letter user group management of the specific code for your reference, the specific contents are as follows

Model Layer Entity class:

 public class UserList
 {public
 string total {get; set;}
 public string Count {get; set;}
 Public Userlistopenid data {get; set;}
 public string Next_openid {get; set;}
 }

 public class Userlistopenid
 {public
 list<string> OpenID {get; set;}
 }

 public class Wxgroupsinfo
 {public
 string group_id {get; set;} Group numbering public
 string Group_name {get; set;} Group name Public
 string Group_count {get; set;} Group number
 }

Wx.aspx content:

&lt;%@ Page language= "C #" autoeventwireup= true "codebehind=" WX.aspx.cs "inherits=" test. WX "%&gt; &lt;! DOCTYPE html&gt; &lt;html xmlns= "http://www.w3.org/1999/xhtml" &gt; &lt;head runat= "Server" &gt; &lt;meta http-equiv= " Content-type "content=" text/html;
 Charset=utf-8 "/&gt; &lt;style type= text/css" &gt; Inputstyle {height:35px;
 line-height:35px;
 text-indent:5px;
 width:350px;
 Background-image:url (' images/inputbg.gif ');
 Background-repeat:repeat-x;
 Border-top:solid 1px #a7b5bc;
 Border-left:solid 1px #a7b5bc;
 Border-right:solid 1px #ced9df;
 Border-bottom:solid 1px #ced9df;
 margin:15px Auto 15px Auto;
 }. g_title {width:100%;
 border-bottom:2px solid #ced9df;
 font-size:20px;
 Font-weight:bold;
 Text-align:left;
 text-indent:5px;
 height:40px;
 line-height:40px;
 } th {height:35px;
 Background-color: #31bb34;
 Background-repeat:repeat-x;

 TR {height:30px;}
 #shownewgroup {width:300px;
 height:200px;
 Background-color:white; Z-index:9999;
 border:2px solid #DDD;
 top:40%;
 left:40%;
 Background-color: #fff;
 position:fixed;
 Margin: -100px auto auto-100px;
 Display:none;
 } #shownewgroupzhezhaoceng {height:200%;
 width:200%;
 left:0px;
 top:0px;
 position:fixed;
 z-index:9998;
 Background:rgb (50, 50, 50);
 Background:rgba (0, 0, 0, 0.5);
 Display:none;
 }. closelogin {height:30px;
 border-bottom:2px solid #31bb34;
 Text-align:right;
 line-height:30px;
 font-size:14px;
 Font-weight:bold;

 } a:hover {Cursor:pointer}
 . inputstyle22 {height:35px;
 line-height:35px;
 text-indent:5px;
 width:280px;
 Background-image:url (' images/inputbg.gif ');
 Background-repeat:repeat-x;
 Border-top:solid 1px #a7b5bc;
 Border-left:solid 1px #a7b5bc;
 Border-right:solid 1px #ced9df;
 Border-bottom:solid 1px #ced9df;
 Float:left;
 Margin:auto 5px Auto 5px; 
 } &lt;/style&gt; &lt;style type= "text/css" &gt; button {font:15px Calibri, Arial, Sans-serif; text-shadow:1px 1px 0 RGBA (255, 255, 255, 0.4);
 Text-decoration:none!important;

 White-space:nowrap;
 Display:inline-block;
 Vertical-align:baseline;
 position:relative;
 Cursor:pointer;

 PADDING:4PX 20px; 
 Background-repeat:no-repeat;
 Background-position:bottom left;

 Background-image:url (' button_bg.png ');
 Background-position:bottom left, top right, 0 0, 0 0;

 Background-clip:border-box;
 -moz-border-radius:8px;
 -webkit-border-radius:8px;

 border-radius:8px;
 -moz-box-shadow:0 0 1px #fff inset;
 -webkit-box-shadow:0 0 1px #fff inset;

 box-shadow:0 0 1px #fff inset;
 -webkit-transition:background-position 1s;
 -moz-transition:background-position 1s;
 Transition:background-position 1s;

 }. Blue.button {color: #0f4b6d!important;

 border:1px solid #84acc3!important;

 Background-color: #48b5f2; Background-image:url (' button_bg.png '), url (' button_bg.png '),-moz-radial-gradient (center bottom, Circle, Rgba (89, 244, 1) 0, Rgba (244, 0) 100px),-moz-Linear-gradient (#4fbbf7, #3faeeb);
    Background-image:url (' button_bg.png '), url (' button_bg.png '),-webkit-gradient (radial, 50% 100%, 0, 50% 100%, 100, From (RGBA, 244, 1), to (RGBA, 244, 0)),-webkit-gradient (linear, 0% 0, 0% 100%, from (#4fbbf7), to (#3f
 Aeeb));

 }. blue.button:hover {background-color: #63c7fe;  Background-image:url (' button_bg.png '), url (' button_bg.png '),-moz-radial-gradient (center bottom, Circle, Rgba (109,

 217, 1) 0, RGBA (109, 217, 0) 100px),-moz-linear-gradient (#63c7fe, #58bef7);
    Background-image:url (' button_bg.png '), url (' button_bg.png '),-webkit-gradient (radial, 50% 100%, 0, 50% 100%, 100, From (RGBA (109, 217, 1)), to (RGBA (109, 217, 0)),-webkit-gradient (linear, 0% 0, 0% 100%, from (#63c7fe), to (#
 58BEF7));

 } &lt;/style&gt; &lt;script src= "js/jquery-1.11.2.min.js" &gt;&lt;/script&gt; &lt;script type= "Text/javascript" &gt; Modifies function functions Editroster (Payno, name) {//alert for Group name calls (Payno+ ":" +name); var url = ' edit.aspx?id= ' + payno + ' &amp;name= ' + name; 
 Turn to the address of the Web page; var name = ' Add '; 
 The name of the Web page may be empty; var iwidth = 600; 
 The width of the pop-up window; var iheight = 300; 
 The height of the pop-up window;
 Gets the vertical position of the window var itop = (window.screen.availheight-30-iheight)/2;
 Gets the horizontal position of the window var ileft = (window.screen.availwidth-10-iwidth)/2; window.open (URL, name, ' height= ' + iheight + ', innerheight= ' + iheight + ', width= ' + iwidth + ', innerwidth= ' + iwidth + ', Top= ' + itop + ', left= ' + ILeft + ', Status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=0,titlebar=no '
 );
  $ (document). Ready (function () {$ (". Newgroups"). Click (function () {$ ("#shownewgroupzhezhaoceng"). Show ();
  $ ("#shownewgroup"). Show ();
  }), $ ('. Closeloginpage '). Click (function () {$ ("#shownewgroupzhezhaoceng"). Hide ();
  $ ("#shownewgroup"). Hide ();
 });
 }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;form id= "Form1" runat= "Server" &gt; &lt;div class= "g_title" &gt; Group Management &lt; /div&gt; &lt;div id= "Shownewgroup"; &lt;div class= "Closelogin" &gt; &lt;span style= "Float:left"; Color: #08a5e0; font-size:18px; text-indent:5px; " &gt; New group &lt;/span&gt; &lt;a class= "closeloginpage button Blue" &gt; off &lt;/a&gt; &lt;/div&gt; &lt;div style= "font -size:12px; height:40px; color:red; line-height:40px; " &gt; within 30 characters &lt;/div&gt; &lt;input type= "text" id= "Txtgroupsname" name= "Txtgroupsname" class= "Inputstyle22" maxlength = "runat=" server "value=" group name "onfocus=" if (value==defaultvalue) {value= '; this.style.color= ' #000 '} ' onblur= ' if (! Value) {value=defaultvalue;this.style.color= ' #999 '} "style=" color: #999 "/&gt; &lt;asp:linkbutton id=" Linkbtncreategroup "runat=" Server "onclick=" Linkbtncreategroup_click "&gt; &lt;div style=" Background-image:url (' Images/buttonbg.png '); width:111px; height:35px; line-height:35px; Font-weight:bold; Float:left; margin-top:20px; margin-left:5px; Text-align:center; Color: #fff; &gt; OK create &lt;/div&gt; &lt;/asp:LinkButton&gt; &lt;/div&gt; &lt;div id= "shOwnewgroupzhezhaoceng "&gt;&lt;/div&gt; &lt;table style=" WIDTH:1124PX; margin:10px Auto 10px Auto; border:1px solid #ecd9df; Text-align:center; " &gt; &lt;asp:repeater id= "repeatergrouplist" runat= "Server" onitemcommand= "Repeatergrouplist_itemcommand" onitemdatabound= "Repeatergrouplist_itemdatabound" &gt; &lt;HeaderTemplate&gt; &lt;tr&gt; &lt;th&gt; serial number &lt;/th&gt; &L
  T;th&gt;id number &lt;/th&gt; &lt;th&gt; Group name &lt;/th&gt; &lt;th&gt; Group number &lt;/th&gt; &lt;th&gt; operation &lt;/th&gt; &lt;/tr&gt; &lt;/HeaderTemplate&gt; &lt;ItemTemplate&gt; &lt;tr style= ' Background-color: &lt;%# (container.itemindex%2 = 0)? "#fff": "#ced9ff"%&gt; ' &gt; &lt;td&gt;&lt;asp:label id= "Lbxuhao" runat= "Server" text= "" &gt;&lt;/asp:label&gt;&lt;/ Td&gt; &lt;td&gt;&lt;%# eval ("group_id")%&gt;&lt;/td&gt; &lt;td&gt;&lt;%# eval ("group_name")%&gt;&lt;/td&gt; &lt;t d&gt;&lt;%# Eval ("Group_count")%&gt;&lt;/td&gt; &lt;td&gt; &lt;a class= "button blue" onclick= "Editroster (' &lt;%# Eva L ("group_id")%&gt; ', ' &lt;%# Eval ("group_name")%&gt; '); "&gt; Modify group name &lt;/a&gt; &lt;asp:linkbutton id=" Linkbtndeletegroup "runat=" Server "Commandname=" Deletegroups " Commandargument= ' &lt;%# Eval ("group_id")%&gt; ' cssclass= button Blue ' &gt; Delete group &lt;/asp:LinkButton&gt; &lt;asp: LinkButton id= "Linkbtnsendbygroup" runat= "Server" Commandname= "sendbygroups" commandargument= "&lt;%#" Eval ("group_id ")%&gt; ' cssclass= button Blue" &gt; Group message Mass &lt;/asp:LinkButton&gt; &lt;asp:linkbutton id= "Linkbtnmoveusertogroup" runat= "Server" Commandname= "Moveusertogroup" commandargument= ' &lt;%# Eval ("group_id")%&gt; ' cssclass= ' button blue ' 
 &gt; Mobile Group &lt;/asp:LinkButton&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/ItemTemplate&gt; &lt;/asp:Repeater&gt; &lt;/table&gt; &lt;a class= "newgroups" &gt;&lt;div style= "Background-image:url" (' images/buttonbg.png '); width:111px; height:35px; line-height:35px; margin:10px Auto 10px 28px; Font-weight:bold; Float:left; Text-align:center; Color: #fff; &gt;&nbsp;┼&nbsp; New Group &LT;/DIV&GT;&LT;/A&GT

 &lt;/form&gt; &lt;/body&gt; &lt;/html&gt;

WX.aspx.cs Code:

Public partial class WX:System.Web.UI.Page {protected void Page_Load (object sender, EventArgs e) {bindgrouplist ()
 ; This.
 DataBind ();

 private void Bindgrouplist () {weixinserver wxs = new Weixinserver ();

 Read Accesstoken string access_token = cache["Access_token" as string from cache; if (Access_token = null) {//if empty, retrieve Access_token = Wxs.
 Getaccesstoken ();
  Set cached data 7,000 seconds after expiration Cache.Insert ("Access_token", Access_token, NULL, DateTime.Now.AddSeconds (7000),
 System.Web.Caching.Cache.NoSlidingExpiration); String access_tokento = Access_token. Substring, Access_token.

 LENGTH-37);

 String jsonres = "";

 String content = cache["Allgroups_content"] as String;

 if (content = = null) {jsonres = "https://api.weixin.qq.com/cgi-bin/groups/get?access_token=" + access_tokento;
 HttpWebRequest myrequest = (HttpWebRequest) webrequest.create (jsonres);
 Myrequest.method = "Get";
 HttpWebResponse myresponse = (HttpWebResponse) myrequest.getresponse (); StreamReader ReadeR = new StreamReader (Myresponse.getresponsestream (), Encoding.UTF8); Content = Reader.
 ReadToEnd (); Reader.

 Close ();
  Set cached data 7,000 seconds after expiration Cache.Insert ("Allgroups_content", content, NULL, DateTime.Now.AddSeconds (7000),
 System.Web.Caching.Cache.NoSlidingExpiration);


 Newtonsoft.json file Jobject jsonobj = jobject.parse (content) should be referenced before use. int groupsnum = jsonobj["groups"].


 Count ();

 list&lt;wxgroupsinfo&gt; wxgrouplist = new list&lt;wxgroupsinfo&gt; ();

 for (int i = 0; i &lt; Groupsnum i++) {wxgroupsinfo wginfo = new Wxgroupsinfo (); Wginfo. group_id = jsonobj["groups"][i]["ID".

 ToString (); Wginfo. Group_name = jsonobj["groups"][i]["Name".

 ToString (); Wginfo. Group_count = jsonobj["groups"][i]["Count"].

 ToString (); Wxgrouplist.
 ADD (Wginfo); } this.
 Repeatergrouplist.datasource = wxgrouplist; This.
 Repeatergrouplist.databind (); ///&lt;summary&gt;///Binding events///&lt;/summary&gt;///&lt;param name= "sender" &gt;&lt;/param&gt;///&lt;param Nam
E= "E" &gt;&lt;/param&gt; protected void Repeatergrouplist_itemdatabound (object sender, RepeaterItemEventArgs e) {if (E.item.itemtype = = Listite Mtype.item | |

 E.item.itemtype = = ListItemType.AlternatingItem) {Label Lbxuhao = E.item.findcontrol ("Lbxuhao") as label;

 int num = 1; Lbxuhao.text = num.

 ToString (); for (int i = 0; I &lt; this. RepeaterGroupList.Items.Count;
  i++) {num = 1; Lbxuhao.text = num.
 ToString ();
 } LinkButton Linkbtndeletegroup = E.item.findcontrol ("Linkbtndeletegroup") as LinkButton;

 LinkButton Linkbtnsendbygroup = E.item.findcontrol ("Linkbtnsendbygroup") as LinkButton; LINKBTNDELETEGROUP.ATTRIBUTES.ADD ("OnClick", "Return confirm" (' Are you sure you want to delete this group?) After deletion, the people within this group are about to revert to the default group!
 ')"); LINKBTNDELETEGROUP.ATTRIBUTES.ADD ("OnClick", "Return confirm" (' Are you sure you want to mass message to this group?)
 ')"); }///&lt;summary&gt;///execution Event///&lt;/summary&gt;///&lt;param name= "source" &gt;&lt;/param&gt;///&lt;param N Ame= "E" &gt;&lt;/param&gt; protected void Repeatergrouplist_itemcommand (object source, RepeatercommandeveNtargs e) {if (E.commandname = = "Deletegroups") {weixinserver Wxs = new Weixinserver ();

 string res = "";

 Read Accesstoken string access_token = cache["Access_token" as string from cache; if (Access_token = null) {//if empty, retrieve Access_token = Wxs.

  Getaccesstoken ();
  Set cached data 7,000 seconds after expiration Cache.Insert ("Access_token", Access_token, NULL, DateTime.Now.AddSeconds (7000),
 System.Web.Caching.Cache.NoSlidingExpiration); String access_tokento = Access_token. Substring, Access_token.


 LENGTH-37);


 String posturl = "https://api.weixin.qq.com/cgi-bin/groups/delete?access_token=" + access_tokento;

 Post Data example: Post Data example: {"group": {"id": 108}} String GroupID = E.commandargument.tostring ();

 String postdata = "{\ Group\": {\ "id\": \ "+ GroupID +" \ "}}"; res = Wxs.

 GetPage (PostURL, postdata); Scriptmanager.registerclientscriptblock (this. Page, this. GetType (), "", "alert (' Delete succeeded! Because of the caching problem, you may need to log on again to see the effect!
 '); location= ' wxgroupmanagelist.aspx '; ", true); } if (E.commandname = = "SendbyGroups ") {weixinserver Wxs = new Weixinserver ();

 string res = "";

 Read Accesstoken string access_token = cache["Access_token" as string from cache; if (Access_token = null) {//if empty, retrieve Access_token = Wxs.

  Getaccesstoken ();
  Set cached data 7,000 seconds after expiration Cache.Insert ("Access_token", Access_token, NULL, DateTime.Now.AddSeconds (7000),
 System.Web.Caching.Cache.NoSlidingExpiration); String access_tokento = Access_token. Substring, Access_token.


 LENGTH-37);

 String posturl = "https://api.weixin.qq.com/cgi-bin/message/mass/sendall?access_token=" + access_tokento;

 String groupid = E.commandargument.tostring (); String postdata = "{\ Group\": {\ "id\": \ "" + GroupID.

 ToString () + "\"}};
  Jobject postdata = new Jobject ();
  Jobject filter = new Jobject (); Filter.
  ADD ("Is_to_all", false); Filter.

  ADD ("group_id", GroupID);
  Jobject Text = new Jobject (); Text. ADD ("Content", "Test contents!")

  ");
  Postdata.add ("filter", filter);
  Postdata.add ("text", text); Postdata.add ("Msgtype", "TexT "); res = Wxs.

 GetPage (PostURL, postdata.tostring ()); Scriptmanager.registerclientscriptblock (this. Page, this. GetType (), "", "alert (' Mass success! Because of the caching problem, you may need to log on again to see the effect!
 '); location= ' wxgroupmanagelist.aspx '; ", true);
 } if (E.commandname = = "Moveusertogroup") {weixinserver Wxs = new Weixinserver ();
 string res = "";

 String access_token = cache["Access_token"] as String; if (Access_token = = null) {Access_token = Wxs.
  Getaccesstoken (); Cache.Insert ("Access_token", Access_token, NULL, DateTime.Now.AddSeconds (7000),
 System.Web.Caching.Cache.NoSlidingExpiration); String access_tokento = Access_token. Substring, Access_token.
 LENGTH-37);

 String posturl = "https://api.weixin.qq.com/cgi-bin/groups/members/update?access_token=" + access_tokento; String userlisturl = "https://api.weixin.qq.com/cgi-bin/user/get?access_token=" + Access_tokento + "&amp;next_openid=


 "; {"Total": 2, "Count": 2, "data": {"OpenID": ["", "OPENID1", "OPENID2"]}, "Next_openid": "Next_openid"} res = Wxs. GetPage (Userlisturl, "");
 UserList userlist= jsonconvert.deserializeobject&lt;userlist&gt; (res);
 String Openid=userlist.data.openid.firstordefault ();
 int togroup_id = 101;//input Group ID string postdata = "{\" openid\ ": \" "+ OpenID +" \, \ "to_groupid\": "+ togroup_id +"} "; res = Wxs.

 GetPage (PostURL, postdata); Scriptmanager.registerclientscriptblock (this. Page, this. GetType (), "", "alert (' Move Group succeeded! Because of the caching problem, you may need to log on again to see the effect!
 '); location= ' wxgroupmanagelist.aspx '; ", true); }///&lt;summary&gt;///create group///&lt;/summary&gt;///&lt;param name= "sender" &gt;&lt;/param&gt;///&lt;param N Ame= "E" &gt;&lt;/param&gt; protected void Linkbtncreategroup_click (object sender, EventArgs e) {if (this.txtgroupsname. Value.equals ("group name")) {////Scriptmanager.registerclientscriptblock (this. Page, this. GetType (), "", "alert (' cannot be empty!
 ') ', true);
 This.txtgroupsName.Focus ();
 Return
 } weixinserver Wxs = new Weixinserver ();

 string res = ""; Reading from cache Accesstoken string access_token = cache["access_tOken "] As String; if (Access_token = null) {//if empty, retrieve Access_token = Wxs.

 Getaccesstoken ();
  Set cached data 7,000 seconds after expiration Cache.Insert ("Access_token", Access_token, NULL, DateTime.Now.AddSeconds (7000),
 System.Web.Caching.Cache.NoSlidingExpiration); String access_tokento = Access_token. Substring, Access_token.


 LENGTH-37);

 String posturl = "https://api.weixin.qq.com/cgi-bin/groups/create?access_token=" + access_tokento; String postdata = "{\ Group\": {\ "name\": \ "" + this.txtgroupsName.Value.ToString (). 
 Trim () + "\"}}; res = Wxs. 
 GetPage (PostURL, postdata); Scriptmanager.registerclientscriptblock (this. Page, this. GetType (), "", "alert (' Create success! If it is not displayed, please exit and login again!
 '); location= ' wxgroupmanagelist.aspx '; ", true);

 }
 }

WeiXinServer.cs Code:

&lt;summary&gt;///Service class///&lt;/summary&gt; public class Weixinserver {///&lt;summary&gt;///get pass///& lt;/summary&gt;///&lt;returns&gt;&lt;/returns&gt; public string Getaccesstoken () {String url_token = "Https://api. weixin.qq.com/cgi-bin/token?grant_type=client_credential&amp;appid=wx3eb5bf1290db2ca0&amp;secret=
 e6013be0a7338c7d3e02877db116e231 ";
 HttpWebRequest myrequest = (HttpWebRequest) webrequest.create (Url_token);
 Myrequest.method = "Get";
 HttpWebResponse myresponse = (HttpWebResponse) myrequest.getresponse ();
 StreamReader reader = new StreamReader (Myresponse.getresponsestream (), Encoding.UTF8); String content = Reader.
 ReadToEnd (); Reader.
 Close ();
 return content;
 public string GetPage (string p, string postdata) {Stream outstream = null;
 Stream instream = null;
 StreamReader sr = null;
 HttpWebResponse response = null;
 HttpWebRequest request = null;
 Encoding Encoding = Encoding.UTF8; byte[] data = encoding.
 GetBytes (PostData); Prepare the request..
 try {//Set parameter request = WebRequest.Create (p) as HttpWebRequest;
 Cookiecontainer Cookiecontainer = new Cookiecontainer (); Request.
 Cookiecontainer = Cookiecontainer; Request.
 AllowAutoRedirect = true; Request.
 method = "POST"; Request.
 ContentType = "application/x-www-form-urlencoded"; Request. ContentLength = data.
 Length; OutStream = Request.
 GetRequestStream (); OutStream. Write (data, 0, data.
 Length); OutStream.
 Close (); Send request and get corresponding response data response = Request.
 GetResponse () as HttpWebResponse; Until request. The GetResponse () program only starts sending post requests to the target Web page instream = response.
 GetResponseStream ();
 sr = new StreamReader (instream, encoding); Returns the resulting web page (HTML) code string content = Sr.
 ReadToEnd (); string err = string.
 Empty;
 return content; The catch (Exception ex) {string err = ex.
 message; return string.
 Empty;

 }
 }
 }

Edit.aspx content:

&lt;%@ Page language= "C #" autoeventwireup= true "codebehind=" Edit.aspx.cs "inherits=" test. Edit "%&gt; &lt;html &gt; &lt;head runat=" Server "&gt; &lt;meta http-equiv=" content-type "content=" text/html;
 Charset=utf-8 "/&gt; &lt;title&gt;&lt;/title&gt; &lt;style type=" Text/css "&gt;. inputstyle {height:35px;
 line-height:35px;
 text-indent:5px;
 width:280px;
 Background-image:url (' images/inputbg.gif ');
 Background-repeat:repeat-x;
 Border-top:solid 1px #a7b5bc;
 Border-left:solid 1px #a7b5bc;
 Border-right:solid 1px #ced9df;
 Border-bottom:solid 1px #ced9df;
 Float:left;
 Margin:auto 5px Auto 5px; } &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;form id= "Form1" runat= "Server" &gt; &lt;table border= "1" style= "width : 500px; Border-collapse:collapse; margin:20px Auto 20px Auto; line-height:40px; " &gt; &lt;tr&gt; &lt;td style= "text-align:right;" &gt; Group number:&lt;/td&gt; &lt;td&gt; &lt;asp:textbox id= "txtgroupid" cssclass= "Inputstyle" enabled= "false" runat= "Server" &gt;&lt;/asp:TextBox&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td style= "text-align:right;" &gt; Group name:&lt;/td&gt; &lt;td&gt; &lt;asp:textbox id= "Txtgroupname" cssclass= "Inputstyle" runat= "Server" &gt;&lt;/asp: textbox&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;/td&gt; &lt;td&gt; &lt;asp:linkbutton id= "Linkbtnse T "runat=" server "onclick=" Linkbtnset_click "&gt;&lt;div style=" Background-image:url (' images/buttonbg.png '); width:111px; height:35px; line-height:35px; Float:left; Font-weight:bold; Text-align:center; Color: #fff; &gt;&nbsp; &nbsp; Set &lt;/div&gt;&lt;/asp:LinkButton&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/form&gt; &lt;/

 Body&gt; &lt;/html&gt;

Edit.aspx.cs Code:

 Public partial class Edit:System.Web.UI.Page {protected void Page_Load (object sender, EventArgs e) {if (!) Page.IsPostBack) {if (request.querystring["id"]!= null) {string group_id = request.querystring["id"].
  ToString (); String group_name = request.querystring["Name"].
  ToString (); This.txtGroupId.Text = group_id.
  ToString (); This.txtGroupName.Text = Group_name.
  ToString ();
 This.txtGroupName.Focus (); }}///&lt;summary&gt;///settings///&lt;/summary&gt;///&lt;param name= "sender" &gt;&lt;/param&gt;///&lt;param Name= "E" &gt;&lt;/param&gt; protected void Linkbtnset_click (object sender, EventArgs e) {if (String.isnullorwhitespace) ( This.txtGroupName.Text.ToString (). Trim ()) {Scriptmanager.registerclientscriptblock (this. Page, this. GetType (), "", "alert (' cannot be empty!
 '); ", true);
 This.txtGroupName.Focus ();
 Return } if (This.txtGroupName.Text.Trim (). Length &gt; {scriptmanager.registerclientscriptblock (this.) Page, this. GetType (), "", "alert (' group name should be within 30 characters!) '; ", true);
 This.txtGroupName.Focus ();
 Return
 } weixinserver Wxs = new Weixinserver ();

 string res = "";

 Read Accesstoken string access_token = cache["Access_token" as string from cache; if (Access_token = null) {//if empty, retrieve Access_token = Wxs.

 Getaccesstoken ();
  Set cached data 7,000 seconds after expiration Cache.Insert ("Access_token", Access_token, NULL, DateTime.Now.AddSeconds (7000),
 System.Web.Caching.Cache.NoSlidingExpiration); String access_tokento = Access_token. Substring, Access_token.

 LENGTH-37);

 String posturl = "https://api.weixin.qq.com/cgi-bin/groups/update?access_token=" + access_tokento; Post Data example: Post Data example: {"group": {"id": 108, "name": "Test2_modify2"} string postdata = "{\ Group\": {\ "id\": \ "" +
 Txtgroupid.text + "\", \ "name\": \ "+ This.txtGroupName.Text +" \ "}}"; res = Wxs.

 GetPage (PostURL, postdata);

 Use Newtonsoft.json jobject jsonobj = Jobject.parse (res); Gets the correct |true|false that returns the result, string isright = jsonobj["Errcode"]. ToString (); 0 string istrueorfalse = jsonobj["ErrMsg "]. ToString (); Ok if (isright. Equals ("0") &amp;&amp; istrueorfalse. Equals ("OK")) {//After successful modification, refresh the parent form and close this page scriptmanager.registerclientscriptblock. Page, this. GetType (), "", "alert (' Modify success! If not properly displayed, is a cache problem, please login again! "); window.open! [Write a picture description here]
 (http://img.blog.csdn.net/20161008103126694) er.location.reload (); This.close (); ", true); else {Scriptmanager.registerclientscriptblock (this. Page, this. GetType (), "", "alert (' Modify failed!
 '); This.close (); ", true;

 }
 }
 }

Buttonbg.png

The result is as shown in figure:

This article has been sorted out to the ASP. NET micro-Credit Development tutorial Summary, you are welcome to learn to read.

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.