to 最近到一个公司做asp.net,里面些基本全部用ObjectDataSource来处理,我很不喜欢,特讨厌这个东西,还是喜欢把数据操作单独分开,我觉得那样好调试.有时候公司的限制是比较烦人的,公司选取比较好的模式,有利于培养员工,和提高效率。 但是有时候公司以利益优先,往往看不到这一点。 to 还有发现在vs2005,asp.net里用vb写可以用MsgBox这个方法,不过用c#没有.use js "Alert" method
用ObjectDataSource,你应该参考一下那些Starter Kit,例如VS2005自带Personal Web Site那个。人家也是DAL到BLL在到页面,然后ObjectDataSource就是沟通BLL和页面上数据控件的桥梁,为此提供便利。详细的便利就是,你在ObjectDataSource中制定对应BLL的SELECT/INSERT/UPDATE/DELETE方法,然后就可以用别的数据控件去帮定ObjectDataSource了,之后数据控件上的操作就能够自动操作到BLL。
你自己看看噢.在2003里面是没有的噢. 你们的函数能在asp.net里这样用么? If MsgBox("OK", MsgBoxStyle.YesNoCancel, "haha") = MsgBoxResult.Yes Then MsgBox(My.User.Name) End If还没有明白我的意思,我这个msgbox是后台写的代码,不是前台写的.怀疑是把vbscrpit转过来的 是什么自己建个东西看看.不要乱说.
但是有时候公司以利益优先,往往看不到这一点。
to 还有发现在vs2005,asp.net里用vb写可以用MsgBox这个方法,不过用c#没有.use js "Alert" method
{
MsgBox(this,"abc");
}
static public void MsgBox(Page page,string msg)
{
page.RegisterStartupScript("alert","<script language=javascript>alert('"+msg.Replace("'","\\'")+"');</script>");
}
看一下MsgBox反编译的C#代码:[HostProtection(SecurityAction.LinkDemand, Resources=0x80)]
public static MsgBoxResult MsgBox(object Prompt, [Optional] MsgBoxStyle Buttons /* = 0 */, [Optional] object Title /* = null */)
{
IWin32Window window1 = null;
string text1 = null;
string text2;
IVbHost host1 = HostServices.VBHost;
if (host1 != null)
{
window1 = host1.GetParentWindow();
}
if ((((Buttons & ((MsgBoxStyle) 15)) > MsgBoxStyle.RetryCancel) || ((Buttons & ((MsgBoxStyle) 240)) > MsgBoxStyle.Information)) || ((Buttons & ((MsgBoxStyle) 0xf00)) > MsgBoxStyle.DefaultButton3))
{
Buttons = MsgBoxStyle.OkOnly;
}
try
{
if (Prompt != null)
{
text1 = (string) Conversions.ChangeType(Prompt, typeof(string));
}
}
catch (StackOverflowException exception1)
{
throw exception1;
}
catch (OutOfMemoryException exception2)
{
throw exception2;
}
catch (ThreadAbortException exception3)
{
throw exception3;
}
catch (Exception)
{
throw new ArgumentException(Utils.GetResourceString("Argument_InvalidValueType2", new string[] { "Prompt", "String" }));
}
try
{
if (Title == null)
{
if (host1 == null)
{
text2 = Interaction.GetTitleFromAssembly(Assembly.GetCallingAssembly());
}
else
{
text2 = host1.GetWindowTitle();
}
}
else
{
text2 = Conversions.ToString(Title);
}
}
catch (StackOverflowException exception4)
{
throw exception4;
}
catch (OutOfMemoryException exception5)
{
throw exception5;
}
catch (ThreadAbortException exception6)
{
throw exception6;
}
catch (Exception)
{
throw new ArgumentException(Utils.GetResourceString("Argument_InvalidValueType2", new string[] { "Title", "String" }));
}
return (MsgBoxResult) MessageBox.Show(window1, text1, text2, ((MessageBoxButtons) Buttons) & ((MessageBoxButtons) 15), ((MessageBoxIcon) Buttons) & ((MessageBoxIcon) 240), ((MessageBoxDefaultButton) Buttons) & ((MessageBoxDefaultButton) 0xf00), ((MessageBoxOptions) Buttons) & ((MessageBoxOptions) (-4096)));
}
public class MessageBox
{
public static void Show(System.Web.UI.Page page,string msg)
{
page.Response.Write("<script language=javascript>");
page.Response.Write("alert('");
page.Response.Write(msg);
page.Response.Write("');</script>");
} public static void Show(System.Web.UI.UserControl page,string msg)
{
page.Response.Write("<script language=javascript>");
page.Response.Write("alert('");
page.Response.Write(msg);
page.Response.Write("');;history.back();</script>");
}
public MessageBox()
{
}
}
还是不好!毕竟那是桌面开发的一些东西!
建议用javascript:
/// <summary>
/// 弹出JavaScript小窗口
/// </summary>
/// <param name="js">窗口信息</param>
public static void Alert(string message)
{
message = StringUtil.DeleteUnVisibleChar(message);
string js=@"<Script language='JavaScript'>
alert('"+ message +"');</Script>";
HttpContext.Current.Response.Write(js);
}
你们的函数能在asp.net里这样用么?
If MsgBox("OK", MsgBoxStyle.YesNoCancel, "haha") = MsgBoxResult.Yes Then
MsgBox(My.User.Name)
End If还没有明白我的意思,我这个msgbox是后台写的代码,不是前台写的.怀疑是把vbscrpit转过来的
是什么自己建个东西看看.不要乱说.
有点怀疑是vb.net项目组故意加个小花招.
是不是有点孔已子啊
{
MsgBox(this,"abc");
}
static public void MsgBox(Page page,string msg)
{
page.RegisterStartupScript("alert","<script language=javascript>alert('"+msg.Replace("'","\\'")+"');</script>");
}
║ 免费的源码、工具网站,欢迎大家访问!║
║ http://www.j2soft.cn/ ║
╰═══════════════════╯
不喜欢可以不用,个人问题;问题2:在C#中可以这样写:
先引用using Microsoft.VisualBasic;
然后:
if (Interaction.MsgBox("OK", MsgBoxStyle.YesNoCancel, "haha") == MsgBoxResult.Yes)
{
Interaction.MsgBox(Environment.UserName, MsgBoxStyle.OkOnly, "test");
} if (Interaction.MsgBox("OK", MsgBoxStyle.YesNoCancel, "haha") == MsgBoxResult.Yes)
{
Interaction.MsgBox(Environment.UserName, MsgBoxStyle.OkOnly, "test");
}
public static MsgBoxResult MsgBox(object Prompt, [Optional] MsgBoxStyle Buttons /* = 0 */, [Optional] object Title /* = null */)
{
IWin32Window window1 = null;
string text1 = null;
string text2;
IVbHost host1 = HostServices.VBHost;
if (host1 != null)
{
window1 = host1.GetParentWindow();
}
if ((((Buttons & ((MsgBoxStyle) 15)) > MsgBoxStyle.RetryCancel) || ((Buttons & ((MsgBoxStyle) 240)) > MsgBoxStyle.Information)) || ((Buttons & ((MsgBoxStyle) 0xf00)) > MsgBoxStyle.DefaultButton3))
{
Buttons = MsgBoxStyle.OkOnly;
}
try
{
if (Prompt != null)
{
text1 = (string) Conversions.ChangeType(Prompt, typeof(string));
}
}
catch (StackOverflowException exception1)
{
throw exception1;
}
catch (OutOfMemoryException exception2)
{
throw exception2;
}
catch (ThreadAbortException exception3)
{
throw exception3;
}
catch (Exception)
{
throw new ArgumentException(Utils.GetResourceString("Argument_InvalidValueType2", new string[] { "Prompt", "String" }));
}
try
{
if (Title == null)
{
if (host1 == null)
{
text2 = Interaction.GetTitleFromAssembly(Assembly.GetCallingAssembly());
}
else
{
text2 = host1.GetWindowTitle();
}
}
else
{
text2 = Conversions.ToString(Title);
}
}
catch (StackOverflowException exception4)
{
throw exception4;
}
catch (OutOfMemoryException exception5)
{
throw exception5;
}
catch (ThreadAbortException exception6)
{
throw exception6;
}
catch (Exception)
{
throw new ArgumentException(Utils.GetResourceString("Argument_InvalidValueType2", new string[] { "Title", "String" }));
}
return (MsgBoxResult) MessageBox.Show(window1, text1, text2, ((MessageBoxButtons) Buttons) & ((MessageBoxButtons) 15), ((MessageBoxIcon) Buttons) & ((MessageBoxIcon) 240), ((MessageBoxDefaultButton) Buttons) & ((MessageBoxDefaultButton) 0xf00), ((MessageBoxOptions) Buttons) & ((MessageBoxOptions) (-4096)));
}
现在报告结果,没弄过什么是UserInteractive 模式结果如下:
在应用程序未以 UserInteractive 模式运行的情况下显示有模式对话框或窗体是无效的操作。请指定 ServiceNotification 或 DefaultDesktopOnly 样式,以显示服务应用程序发出的通知。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.InvalidOperationException: 在应用程序未以 UserInteractive 模式运行的情况下显示有模式对话框或窗体是无效的操作。请指定 ServiceNotification 或 DefaultDesktopOnly 样式,以显示服务应用程序发出的通知。源错误:
行 26: End Sub
行 27: Private Sub aa()
行 28: If MsgBox("OK", MsgBoxStyle.YesNoCancel, "haha") = MsgBoxResult.Yes Then
行 29: MsgBox("aa")
行 30: End If
我没用05,就没试,不过我想vb可以,C#应该也行.通常都是JS写的