如<script type="text/javascript">
//<![CDATA[
Sys.Application.initialize();
Sys.Application.add_init(function() {$create(JerryWebControl.ProgressBehavior, {"Mode":0}, null, null, $get("ProgressBar1_pgb"));});
Sys.Application.add_init(function() {
$create(JerryWebControl.ProgressBehavior, {"Mode":0}, null, null, $get("ProgressBar2_pgb"));
});
//]]>
</script>这个是我的照别人控件做的一条进度条控件,上面是控件生成的js <asp:ProgressBarTab ID="ProgressBar1" runat="server" CssClass="xp" Mode="Manual" Width="500" />
<script type="text/javascript"> function pageLoad()
{
$find('ProgressBar1').set_percentage(62);
}
</script>上面这个是他们使用的方法
但是当我有多个的时候 pageLoad就只执行最后的
然后我想用ScriptManager.RegisterStartupScript(this, typeof(Page), pgb.ClientID, "$find('" + pgb.ClientID + "').set_percentage(" + Value.ToString() + ");", true);进行注册,
但结果为
<script type="text/javascript">
//<![CDATA[
$find('ProgressBar1_pgb').set_percentage(65);$find('ProgressBar2_pgb').set_percentage(15);
Sys.Application.add_init(function() {
$create(JerryWebControl.ProgressBehavior, {"Mode":0}, null, null, $get("ProgressBar1_pgb"));
});
Sys.Application.add_init(function() {
$create(JerryWebControl.ProgressBehavior, {"Mode":0}, null, null, $get("ProgressBar2_pgb"));
});
//]]>
</script>这里发现我的
$find('ProgressBar1_pgb').set_percentage(65);$find('ProgressBar2_pgb').set_percentage(15);Sys.Application.initialize();
在创建这个控件之前
那如何让他在他的创建之后呢
结果为//<![CDATA[
Sys.Application.initialize();
Sys.Application.add_init(function() {
$create(JerryWebControl.ProgressBehavior, {"Mode":0}, null, null, $get("ProgressBar1_pgb"));
});
Sys.Application.add_init(function() {
$create(JerryWebControl.ProgressBehavior, {"Mode":0}, null, null, $get("ProgressBar2_pgb"));
});
$find('ProgressBar1_pgb').set_percentage(65);$find('ProgressBar2_pgb').set_percentage(15);
//]]>
</script>
谢谢
//<![CDATA[
Sys.Application.initialize();
Sys.Application.add_init(function() {$create(JerryWebControl.ProgressBehavior, {"Mode":0}, null, null, $get("ProgressBar1_pgb"));});
Sys.Application.add_init(function() {
$create(JerryWebControl.ProgressBehavior, {"Mode":0}, null, null, $get("ProgressBar2_pgb"));
});
//]]>
</script>这个是我的照别人控件做的一条进度条控件,上面是控件生成的js <asp:ProgressBarTab ID="ProgressBar1" runat="server" CssClass="xp" Mode="Manual" Width="500" />
<script type="text/javascript"> function pageLoad()
{
$find('ProgressBar1').set_percentage(62);
}
</script>上面这个是他们使用的方法
但是当我有多个的时候 pageLoad就只执行最后的
然后我想用ScriptManager.RegisterStartupScript(this, typeof(Page), pgb.ClientID, "$find('" + pgb.ClientID + "').set_percentage(" + Value.ToString() + ");", true);进行注册,
但结果为
<script type="text/javascript">
//<![CDATA[
$find('ProgressBar1_pgb').set_percentage(65);$find('ProgressBar2_pgb').set_percentage(15);
Sys.Application.add_init(function() {
$create(JerryWebControl.ProgressBehavior, {"Mode":0}, null, null, $get("ProgressBar1_pgb"));
});
Sys.Application.add_init(function() {
$create(JerryWebControl.ProgressBehavior, {"Mode":0}, null, null, $get("ProgressBar2_pgb"));
});
//]]>
</script>这里发现我的
$find('ProgressBar1_pgb').set_percentage(65);$find('ProgressBar2_pgb').set_percentage(15);Sys.Application.initialize();
在创建这个控件之前
那如何让他在他的创建之后呢
结果为//<![CDATA[
Sys.Application.initialize();
Sys.Application.add_init(function() {
$create(JerryWebControl.ProgressBehavior, {"Mode":0}, null, null, $get("ProgressBar1_pgb"));
});
Sys.Application.add_init(function() {
$create(JerryWebControl.ProgressBehavior, {"Mode":0}, null, null, $get("ProgressBar2_pgb"));
});
$find('ProgressBar1_pgb').set_percentage(65);$find('ProgressBar2_pgb').set_percentage(15);
//]]>
</script>
谢谢
//<![CDATA[
Sys.Application.initialize();
Sys.Application.add_init(function() {$create(JerryWebControl.ProgressBehavior, {"Mode":0}, null, null, $get("ProgressBar1_pgb"));});
Sys.Application.add_init(function() {
$create(JerryWebControl.ProgressBehavior, {"Mode":0}, null, null, $get("ProgressBar2_pgb"));
});
//]]>
</script>
<asp:Literal ID="Literal1" runat="server" Text="" />Literal1.Text = "$find('" + pgb.ClientID + "').set_percentage(" + Value.ToString() + ");";
因为这个Literall在生成HTML的时候他还是在<script>前面
如<asp:Literal ID="Literal1" runat="server" Text="哈哈,我在这里" />
</form>以下是结果
那是因为那一段Jscript也是由
ScriptManager.RegisterStartupScript生成的哈哈,我在这里
<script type="text/javascript">
//<![CDATA[
$find('ProgressBar1_pgb').set_percentage(65);$find('ProgressBar2_pgb').set_percentage(15);Sys.Application.initialize();
Sys.Application.add_init(function() {
$create(JerryWebControl.ProgressBehavior, {"Mode":0}, null, null, $get("ProgressBar1_pgb"));
});
Sys.Application.add_init(function() {
$create(JerryWebControl.ProgressBehavior, {"Mode":0}, null, null, $get("ProgressBar2_pgb"));
});
//]]>
</script>
</form>
<%= script %>protected string script = "";
//某个方法里
script = "<script type=\"text/javascript\">$find('" + pgb.ClientID + "').set_percentage(" + Value.ToString() + ");</script>";
但是很实用
public partial class Stat_ProgressBar : System.Web.UI.UserControl
{
public Int32 Value
{
get
{
return ViewState["Value"] != null ? Convert.ToInt32(ViewState["Value"]) : 0;
}
set
{
ViewState["Value"] = value;
}
}
public Int32 Width
{
get
{
return ViewState["Width"] != null ? Convert.ToInt32(ViewState["Width"]) : 0;
}
set
{
ViewState["Width"] = value;
}
}
protected void Page_Load(object sender, EventArgs e)
{
pgb.Width = Width;
ScriptManager.RegisterStartupScript(this, typeof(Page), pgb.ClientID, "$find('" + pgb.ClientID + "').set_percentage(" + Value.ToString() + ");", true);
}
}
public partial class Stat_ProgressBar : System.Web.UI.UserControl
{
public Int32 Value
{
get
{
return ViewState["Value"] != null ? Convert.ToInt32(ViewState["Value"]) : 0;
}
set
{
ViewState["Value"] = value;
}
}
public Int32 Width
{
get
{
return ViewState["Width"] != null ? Convert.ToInt32(ViewState["Width"]) : 0;
}
set
{
ViewState["Width"] = value;
}
} public string Script{ return "$find('" + pgb.ClientID + "').set_percentage(" + Value.ToString() + ");"; }
protected void Page_Load(object sender, EventArgs e)
{
pgb.Width = Width;
}
}
</form>
<%= Stat_ProgressBar1.Script %>
<%= Stat_ProgressBar2.Script %>
<%= Stat_ProgressBar3.Script %>
当然也可以用我6楼的方法,先遍历一下页面上的Stat_ProgressBar控件,然后用StringBuilder把它们的Script都Append起来,然后再在前台输出