November 2008 - Posts

若要查看表的列名,可以使用 sp_help 或下列查询之一:SELECT name FROM sys.columns WHERE OBJECT_ID IN (SELECT OBJECT_ID ('table_name')) 或 SELECT TOP 0 * FROM table_name。
1.   Execute sp_help tablename  如: Execute sp_help 'Schedule'
2.   Select Top 0 * From tablename 如:Select Top 0 * From 'Schedule'
3.   Select name From sys.columns where Object_Id In (Select Object_Id(tablename)) 如: Select name From sys.columns where Object_Id In (Select Object_Id('Schedule'))
三种的区别如下:
1.   可以得到table的详细信息,可以得到五个表
2.   一个无记录行的表结构
3.   一个单列表,列名name,内容是表的列名称

I have a web project, in the project, there is a MasterPage and some WebContentPages.
In the MasterPage, there is a function, when you click a button, show or hide the left content.When you refresh or navigate other WebContentPage, the left content keeps its display style.
Here is my first solution:
MasterPage.Master:

<div id="left" style='<%=string.Format("display:{0}",GetToolbarDisplayFlag())%>'>

</div>

<div id="buttons_left">
     <img alt="Move Left" onclick="switchView('left',this);" src='<%=GetImgSrc()%>' />

</div>

Remember to set the EnablePageMethods = "True"


MasterPage.Master.CS:

public string GetToolbarDisplayFlag()
{

       return HttpContext.Current.Session["ToolbarDisplay"] == null ? "block" : HttpContext.Current.Session["ToolbarDisplay"].ToString();

}
public string GetImgSrc()
{
   if(GetToolbarDisplayFlag() == string.Empty || GetToolbarDisplayFlag() == "block")
   {
       return "../App_Themes/images/s_left.gif";
   }
   return "../App_Themes/images/s_right.gif";

}

[WebMethod]public static void SetToolbarDisplayFlag(string flag)
{
    HttpContext.Current.Session["ToolbarDisplay"= flag;

}


JS:


function switchView(objname,current)
{
    var obj = $get(objname);
    if(obj.style.display=="block" || obj.style.display=="")
    {
        obj.style.display="none";
        current.src ='../App_Themes/images/s_right.gif';
        PageMethods.SetToolbarDisplayFlag("none",OnSucceeded,OnFailed);
    }
    else
    {
        obj.style.display="block";
        current.src ='../App_Themes/images/s_left.gif';
        PageMethods.SetToolbarDisplayFlag("block",OnSucceeded,OnFailed);
    }
}
function OnSucceeded(result, userContext, methodName)
{   
    return;
} 
function OnFailed(error, userContext, methodName)
{
    return;
}           

if (typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();


When you click the button, it will cause exception: PageMethods not defined.

This is because the method "SetToolbarDisplayFlag" Js invoke is in MasterPage, it seems PageMethods donot contain MasterPage methods.

 

So, my solution is move the method "SetToolbarDisplayFlag" from MasterPage to a base page called "PageBase" which inherited from System.Web.UI.Page, and each WebContentPage derived from PageBase.

PageBase.cs:


public class PageBase : Page

{

   [WebMethod]
   public static void SetToolbarDisplayFlag(string flag)
   {
       HttpContext.Current.Session["ToolbarDisplay"] = flag;

   }

}


Now, you can invoke methods in MasterPage.

      最近用ModelPopupExtender时,总是提示我有 Sys.InvalidOperationException 未通过 Sys.UI.DomEvent.addHandler 的错误,后来发现是我设置了CancellControlID,而没有设置相应的事件,我是通过在服务器端Show和Hide来控制的,这样脚本在寻找CancellControlID的时候就找不到了,就为null,在脚本中就会抛出以上错误。所以,如果我们要在服务器端控制ModelPopupExtender,不要设置ControlId就可以了!

       很久没有做Web开发了,本以为有以前的基础加上WinForm的开发经验,Web应该不是什么问题的,应该很Easy。但是现在我发现我错了,Web开发已经不是简单的事情了。现在Web开发出来的一些优秀产品已经比较接近WinForm了,这就提高了Web开发的门槛。所以,现在如果我们想做好Web的开发,至少应该了解以下几方面的开发知识:

  • Asp.Net
  • Asp.Net Ajax
  • Asp.Net Ajax Client Library
  • Asp.Net Ajax Future Controls and Ajax Controls Toolkit
  • Javascript
  • Css
  • WebStandard
  • XML/XHTML/HTML
  • Regular Expression
  • JSON Service(Soap)
  • Silverlight
  • Third party product, for example JQuery, Ajax Pro

了解以上东西也并不代表就能做好Web开发,怎么灵活运用这些知识,深入发掘他们之间的交互才是最重要的东西。看来Web开发的路,我还要学习很久啊!

More Posts