我的代码目前要求我点击按钮将信息发回服务器,有没有办法用代码自动执行此操作,基本上是模拟点击按钮或更好,没有任何按钮后发回来?
ASPX代码:
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb" Inherits="WebApplication3.WebForm1" %>
<%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>
<!DOCTYPE html>
<form id="form1" runat="server">
<telerik:RadScriptManager ID="RadScriptManager1" runat="server">
<Scripts>
<asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js">
</asp:ScriptReference>
<asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js">
</asp:ScriptReference>
<asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js">
</asp:ScriptReference>
</Scripts>
</telerik:RadScriptManager>
<asp:HiddenField runat="server" ID="svgHolder" />
<asp:Button ID="Button1" Text="Export the RadHtmlChart" OnClientClick="getSvgContent(this);"
runat="server" />
<table class="clearTable2" style="page-break-after: avoid;">
<tr>
<td class="clearTable1"></td>
<td class="clearTable2">
<asp:Label ID="lblSectionTitle" runat="server" CssClass="label2"></asp:Label>
</td>
<td class="clearTable1"></td>
</tr>
</table>
<table class="clearTable2">
<tr>
<td class="clearTable1"></td>
<td class="clearTable1" style="width: 100%; visibility: visible">
<telerik:RadHtmlChart runat="server" ID="RadHtmlChart1">
<Legend>
<Appearance Position="Bottom">
<TextStyle FontSize="14" Color="Blue" FontFamily="Courier New, sans-serif" />
</Appearance>
</Legend>
<PlotArea>
<XAxis>
<Items>
<telerik:AxisItem LabelText="KM41872"/>
<telerik:AxisItem LabelText="KM41873"/>
<telerik:AxisItem LabelText="KM41871"/>
</Items>
<MajorGridLines Visible="false" />
<MinorGridLines Visible="false" />
</XAxis>
<YAxis>
<MinorGridLines Visible="false" />
</YAxis>
<Series>
<telerik:LineSeries Name="Mean">
<SeriesItems>
<telerik:CategorySeriesItem Y="0.59" />
<telerik:CategorySeriesItem Y="0.63" />
<telerik:CategorySeriesItem Y="0.6" />
<telerik:CategorySeriesItem Y="0.65" />
<telerik:CategorySeriesItem Y="0.64" />
<telerik:CategorySeriesItem Y="0.63" />
<telerik:CategorySeriesItem Y="0.65" />
<telerik:CategorySeriesItem Y="0.67" />
<telerik:CategorySeriesItem Y="0.63" />
</SeriesItems>
</telerik:LineSeries>
<telerik:LineSeries Name="Min">
<SeriesItems>
<telerik:CategorySeriesItem Y="0.55" />
<telerik:CategorySeriesItem Y="0.56" />
<telerik:CategorySeriesItem Y="0.55" />
<telerik:CategorySeriesItem Y="0.61" />
<telerik:CategorySeriesItem Y="0.56" />
<telerik:CategorySeriesItem Y="0.57" />
<telerik:CategorySeriesItem Y="0.59" />
<telerik:CategorySeriesItem Y="0.61" />
<telerik:CategorySeriesItem Y="0.55" />
</SeriesItems>
</telerik:LineSeries>
<telerik:LineSeries Name="Max">
<SeriesItems>
<telerik:CategorySeriesItem Y="0.66" />
<telerik:CategorySeriesItem Y="0.74" />
<telerik:CategorySeriesItem Y="0.66" />
<telerik:CategorySeriesItem Y="0.71" />
<telerik:CategorySeriesItem Y="0.72" />
<telerik:CategorySeriesItem Y="0.73" />
<telerik:CategorySeriesItem Y="0.71" />
<telerik:CategorySeriesItem Y="0.74" />
<telerik:CategorySeriesItem Y="0.71" />
</SeriesItems>
</telerik:LineSeries>
</Series>
</PlotArea>
</telerik:RadHtmlChart>
</td>
<td class="clearTable1"></td>
</tr>
</table>
<script type="text/javascript">
function getSvgContent(sender) {
//obtain an SVG version of the chart regardless of the browser
var chartRendering = $find("<%=RadHtmlChart1.ClientID %>").getSVGString();
//store the SVG string in a hidden field and escape it so that the value can be posted to the server
document.getElementById('<%=svgHolder.ClientID%>').value = escape(chartRendering);
//initiate the postback from the button so that its server-side handler is executed
__doPostBack(sender.name, "");
$('#Button1').click();
}
</script>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</form>
代码隐藏: 公共类WebForm1 继承System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Button1.Text = HttpUtility.UrlDecode(svgHolder.Value)
End Sub
'Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
' Dim svgText As String = HttpUtility.UrlDecode(svgHolder.Value)
'End Sub
End Class
答案 0 :(得分:1)
function DoPostBack(obj) {
__doPostBack(obj.id, 'OtherParams');
}
Just call __doPostBack
答案 1 :(得分:0)
你想要的是__dopostback javascript函数(google it)。它本质上是从.Net控件中伪造一个回发事件,因此它就像点击你的按钮一样工作。你也可以设置按钮的diplay:hidden属性,如果你不希望它显示但仍然挂钩进行回发。