我读了帖子
但我的问题仍然存在.我尝试在回发时多次执行javascript,并且脚本仅在第一次加载页面时执行.
为确保脚本在每个帖子后注册,我使用guid作为javascript密钥名称.
var xyz = DateTime.Now.ToLongTimeString();
string script = @"BrokerCustomValue.value='" + CustomValueToBrokerListSerialized + "';alert('" + xyz + "');";
ScriptManager.RegisterStartupScript(this, GetType(), Guid.NewGuid().ToString(), script, true);
Run Code Online (Sandbox Code Playgroud)
我需要在更新面板中单击链接按钮后确定我的回发事件是否已激活.如果我把我的链接直接放在页面中它正在工作
将脚本管理器放在母版页中是正确的吗?
创建一个新的Web应用程序(我使用的是Visual Studio 2008版本9.0.30729.1 SP)
在Aspx页面中,将Form标签替换为:(可能需要更改类型名称以匹配您的页面名称)
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="True" />
<div>
<asp:DropDownList runat="server" DataSourceID="ObjectDataSource1">
</asp:DropDownList>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="Data" TypeName="WebApplication1.WebForm2"
OnObjectCreating="ObjectDataSource1_ObjectCreating"></asp:ObjectDataSource>
</div>
</form>
Run Code Online (Sandbox Code Playgroud)
在服务器页面上,添加以下功能:
public IEnumerable<string> Data()
{
return new string[] { "some data", "foo", "bar" };
}
Run Code Online (Sandbox Code Playgroud)
然后添加此事件处理程序:
protected void ObjectDataSource1_ObjectCreating(object sender, ObjectDataSourceEventArgs e)
{
e.ObjectInstance = this;
}
Run Code Online (Sandbox Code Playgroud)
现在运行应用程序.我得到"Sys is undefined"脚本错误.自动脚本的大部分完全丢失.
现在注释掉对象实例行,
protected void ObjectDataSource1_ObjectCreating(object sender, ObjectDataSourceEventArgs e)
{
//e.ObjectInstance = this;
}
Run Code Online (Sandbox Code Playgroud)
现在,当您运行应用程序时,没有脚本错误.
这里发生了什么?
c# asp.net objectdatasource scriptmanager visual-studio-2008
,嗨,
我有一个asp.net和c#网站.
在我使用的asp代码中
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true"></asp:ScriptManager>
Run Code Online (Sandbox Code Playgroud)
当我运行我的项目时,我收到此错误:
字符串未被识别为有效的DateTime.
我在我的网站上没有使用任何dataTime的东西.
然后,当我刷新页面时,错误消失.
堆栈跟踪:
[FormatException: String was not recognized as a valid DateTime.] System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles) +3610514 System.Windows.Forms.TypeLibraryTimeStampAttribute..ctor(String timestamp) +49 System.Reflection.CustomAttribute._CreateCaObject(RuntimeModule pModule, IRuntimeMethodInfo pCtor, Byte** ppBlob, Byte* pEndBlob, Int32* pcNamedArgs) +0 System.Reflection.CustomAttribute.CreateCaObject(RuntimeModule module, IRuntimeMethodInfo ctor, IntPtr& blob, IntPtr blobEnd, Int32& namedArgs) +46 System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent) +529 System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeAssembly assembly, RuntimeType caType) +103 System.Reflection.RuntimeAssembly.GetCustomAttributes(Boolean inherit) +33 System.Web.UI.AssemblyCache.GetAjaxFrameworkAssemblyAttribute(Assembly assembly) +76 System.Web.UI.ScriptManager.get_DefaultAjaxFrameworkAssembly() …
我试图在page_load上显示两个警报,但ScriptManager只是执行我的第一个警报.我真的不知道该怎么做,有人可以帮助我吗?
这是我的测试代码.它位于Load方法内:
Page currentPage = (Page)HttpContext.Current.Handler;
ScriptManager.RegisterStartupScript(currentPage, typeof(string), "Script" + DateTime.Now.Millisecond,
"alert('1!');", true);
ScriptManager.RegisterStartupScript(currentPage, typeof(string), "Script" + DateTime.Now.Millisecond,
"alert('2!');", true);
Run Code Online (Sandbox Code Playgroud) 什么是使用$get('').value在ASP.NET AJAX?它是否与通常的C#get和set属性相同?
我在div弹出窗口中的UpdatePanel中有一个链接按钮.在Button_Click上,我希望通过javascript打开一个新窗口.我尝试了ScriptManager.RegisterStartupScript以及ScriptManager.RegisterClientScriptBlock,但是Window没有打开.
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<form class="message-form" action="#">
<fieldset>
<asp:LinkButton ID="LinkButton1" runat="server" class="btn-facebook" Text="facebook" OnClick="LinkButton1_Click"></asp:LinkBu
tton>
<label for="TextBox1">Or send a message on Blissdate here:</label>
<div class="textarea">
<asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine" Rows="10" Columns="30"></asp:TextBox><asp:Label ID="lbl" runat="server" />
</div>
<div class="btn-holder">
<asp:LinkButton ID="LinkButton2" runat="server" class="btn-send" Text="send" OnClick="LinkButton2_Click"></asp:LinkButton>
</div>
</fieldset>
</form>
Run Code Online (Sandbox Code Playgroud)
protected void LinkButton1_Click(object sender, EventArgs e)
{
DataRow[] row1 = ds.Tables[0].Select("FB_Id='" + HiddenField3.Value + "'");
string url = row1[0].ItemArray[3].ToString();
lbl.Text = url;
//ScriptManager.RegisterClientScriptBlock(this, GetType(), "newPage", "window.open('" + url +');", true);
ScriptManager.RegisterClientScriptBlock(this, GetType(), "newpage", …Run Code Online (Sandbox Code Playgroud) asp.net ×5
c# ×5
asp.net-ajax ×2
javascript ×2
coding-style ×1
datetime ×1
master-pages ×1
postback ×1
updatepanel ×1