- 热门文章:
- · 关于上下文(Context)/2(转MS)
- · 关于上下文(Context)/1(转MS)
- · 在.NET中使用静态变量来代替Application变量
- · ASP.NET窗体对话框的实现
- · 用.NET创建定时缓存
- · 将Session值储存于SQL Server中
- · ASP.NET中的事务处理和异常处理
- · ASP.NET Caching /2
- · 嘿,懒鬼!!其实MSDN阐述得真得不错哎,不知道你从哪来的资料
- · ASP.NET Caching /1
- · 绝对酷,如何解决asp.net中javascript脚本的问题(使用服务器控件执行客户端脚本)
- · 最佳ASP.NET编程习惯
runat=server
当我们在窗体上添加web control例如label时,vs.net会自动添加runat=server把它当成服务器控件,但是当我们添加自定义的控件时,我们就无法自动得到runat=server我们必须每个空间都重复添加runat=server。
我们现在要做的就是做一个宏在vs.net中,它可以自动添加runat=server在我们指定的控件上,现在已经存在的runat=server他会忽略不计,不会重复添加。
@#This macro checks the specified elements if they have runat=server in
@#them and if not then automatically adds runat=server in them
Sub AddRunAtServer()
@#Create an Undo context object so all the changes can be
@#undone by CTRL+Z
Dim oUnDo As UndoContext = DTE.UndoContext
oUnDo.Open("Comment Line")
@#Supress the User Interface. This will make it run faster
@#and make all the changes appear once
DTE.SuppressUI = True
Try
@#Make a call to UpdateDocument()
UpdateDocument("<asp:")
UpdateDocument("<form")
UpdateDocument("<script")
UpdateDocument("<body")
@#Finally Close the undo
oUnDo.Close()
Catch oException As system.Exception
Dim lcErrMsg As String
lcErrMsg = "An error occured while running this program." _
& " Please make sure that you are specifying the" _
& " correct parameters."
MsgBox(lcErrMsg)
@#Undo the changes made to the document
oUnDo.SetAborted()
DTE.SuppressUI = False
Finally
@#Rest the Supress UI
DTE.SuppressUI = False
End Try
End Sub
@#This method is used internally to do the actual work for adding
@#runat=server for a specified element type
Private Sub UpdateDocument(ByVal tcStringToSearch As String)
@#Get a reference to the currently open document
Dim oDoc As TextDocument
oDoc = DTE.ActiveDocument.Object("TextDocument")
@#Create editpoints for starting and ending positions of the doc
Dim lnStartPos As EditPoint = oDoc.StartPoint.CreateEditPoint
Dim lnEndPos As EditPoint = oDoc.EndPoint.CreateEditPoint
@#This is the string that we will search and a placeholder string
Dim lcSearchStr As String = tcStringToSearch
Dim lcString As String
@#Define the private variables used in this process
Dim lnStrPos As Integer = 0
Dim lnRunAtPos As Integer = 0
Dim lnClosingPos As Integer = 0
Dim lnEmptySpot As Integer = 0
Do While True
@#Get the string and remove all the carriage returns as they
@#are ignored by the EditPoint object
lcString = LCase(lnStartPos.GetText(lnEndPos))
lcString = Replace(lcString, Chr(13), "")
@#Get the first position of item we are looking for
lnStrPos = InStr(lcString, lcSearchStr)
If lnStrPos = 0 Then
@#If we do not find the item, exit
Exit Do
Else
@#We found the item that we were looking for
@#Shorten the string starting from the new position
lcString = lcString.Remove(0, lnStrPos _
+ Len(lcSearchStr))
@#Now move the EditPoint to that position as well
lnStartPos.CharRight(lnStrPos + Len(lcSearchStr))
@#Now we have the subsized string, let us check for the
@#first occurance of > is more than the runat
lnClosingPos = InStr(lcString, ">")
lnRunAtPos = InStr(lcString, "runat")
@#The closing tag@#s position always HAS to be more
@# than the runat@#s position
If lnRunAtPos = 0 Or lnRunAtPos > lnClosingPos Then
@#At this point we found that Runat=server is
@# missing in this element/object
@#Locate the first blank spot to make the insertion.
lnEmptySpot = InStr(lcString, " ")
@#Make sure that the blank spot is within the
@#boundries
If lnEmptySpot > lnClosingPos Then
@#Special handling required
@#In this case we want to place just before
@# the closing position i.e. ">"
@#However, it is possible that the closing is
@# done using />
If lcString.Substring(lnClosingPos - 2, 1) = _
"/" Then
lnStartPos.CharRight(lnClosingPos - 2)
lnStartPos.Insert(" ")
Else
lnStartPos.CharRight(lnClosingPos - 1)
lnStartPos.Insert(" ")
End If
Else
lnStartPos.CharRight(lnEmptySpot)
End If
@#Once the blank spot is determined and the
@# EditPoint is positioned, Make the insertion
lnStartPos.Insert("runat=server ")
End If
End If
Loop
End Sub
下一篇:关于上下文(Context)/2(转MS) >>
相关文章:
- · 一次同时上传多个文件
- · 在datagrid中求和(vb.net,c#)
- · ASP.NET中利用SQLXML WEB服务访问XML数据(转)
- · 在DataGrid中经弹出窗口确认后执行操作(删除)。(附在DataGrid中修改,添加记录)详见代码!!
- · 在datagrid中放入一个DropDownList(忘了这个问题在那里看到的了CSDN or There)
- · 简单的动态加载用户控件的方法
- · 关于如何 确认删除的另外一个办法。
- · 掉掉注意了,如何动态加载用户控件(ascx)
- · 给大家一个新的加密方法,C#的。(国外的,只用于学习,支持中文)
- · TO feixr,DataGrid中的Radiobutton
- · 微软.NET战略和ASP.NET简介(1)
- · 微软.NET战略和ASP.NET简介(3)
- · 微软.NET战略和ASP.NET简介(2)
- · 验证控件介绍--RegularExpressionValidator
- · 验证控件介绍--RangeValidator
- · 验证控件介绍--CompareValidator
- · 验证控件介绍--RequiredFieldValidator
- · 解决分页的例子。使用DataSet绑定到DataList实现的。数据库使用我刚才贴的这个。
- · 配置Config.web
- · WebRequest Class
- · asp.net中使用静态变量
- · 利用HttpRequest登录到某个网站,然后获取网站信息的程序示例 [原创]
- · Creating DataGrid Templated Columns Dynamically - Part II(转自DotNetTips)
- · 用ASP.NET写你自己的代码生成器(2)。
- · 用ASP.NET写你自己的代码生成器(3)。
- · mark新官上任,转贴一个DataGrid(增加删除确认和新增记录功能),道贺:)
- · 一个datagrid 删除确认例子
- · 关于ASP.Net不能启动调试的官方解答
- · 在WEB窗体中如何转换页面和结束程序?
- · 关于ASP.Net写注册表权限问题的官方解决方法
- · 动态生成柱状图
- · 一个SDK里做聊天室的例子(2)
- · 网上下载和上传数据(一) Montaque(原作)
- · 一个SDK里做聊天室的例子(1)
- · 网上下载和上传数据(二) Montaque(原作)
- · 有空的时候看看,:)ASP.NET Page Templates
- · VB.NET开发互联网应用
- · vb.net cookie操作
