日期:2014-05-16  浏览次数:20391 次

求讲解下边的代码
<head runat="server">
  <title>内容编辑质检</title>
  <meta http-equiv="x-ua-compatible" content="ie=7" />
  <%--清楚缓存--%>
  <meta http-equiv="cache-control" content="no-cache, must-revalidate" />
  <%--清楚缓存--%>
  <meta http-equiv="expires" content="0" />
  <%--清楚缓存--%>
  <base target="_self" />
  <%--页面刷新总是在本窗口--%>
</head>
<%
string sguid = Request.QueryString["SGUID"].ToString();
string qualitysguid = Request.QueryString["QUALITYSGUID"].ToString();
%><frameset border="0" cols="180,*" framespacing="2" frameborder="0" name="UserMain" >
<frame name="contents" src="Trees_List_New.aspx?SGUID=<%=sguid %>&QUALITYSGUID=<%=qualitysguid %>" frameBorder="yes" scrolling="auto" bordercolor="#333399" >
<FRAMESET rows="*,0" frameBorder="0" name="frameContent">
<frame name="userinfo" src="Editorial_List.aspx?SGUID=<%=sguid %>&QUALITYSGUID=<%=qualitysguid %>" ></FRAME>
</FRAMESET>
</frameset>
</html>
上述代码中红色的部门为何这样写能获得URL传递过来的值,还有是否该写法任何情况都适用么?

------解决方案--------------------
QueryString应该是用来获得查询串的值的 
如果你的表单使用get方式提交或者其他方式等导致url中有?号且后边格式一般为name=value多个的话用&符号分隔,那从?到末尾的那串字符串就是查询串了 可以用那个方法获得value
------解决方案--------------------
你可以写成
string sguid = Request.Params.Get("SGUID");
string qualitysguid = Request.Params.Get("QUALITYSGUID");
if(sguid == null) sguid = "";
if(qualitysguid == null) qualitysguid = "";

防止ToString出错
------解决方案--------------------
不适用的,要先判断一下有没有传值,如果没有传传会产生异常.