hysoftwareeng
hysoftwareeng

Reputation: 497

Postback without clicking button in VB.NET?

My code currently requires me to click the button to post the information back to the server, is there any way of doing this automically with code, basically to simulate clicking the button or better, post it back without any buttons?

ASPX code:

           <%@ 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>

CodeBehind: Public Class WebForm1 Inherits 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

Upvotes: 0

Views: 844

Answers (2)

infocyde
infocyde

Reputation: 4171

What you want I think is the __dopostback javascript function (google it). It essentially fakes a post back event from a .Net control so it will work just like as if your button was clicked. You could also set the diplay:hidden property of the button if you don't want it show but still hook into it for a postback.

Upvotes: 0

KingOfHypocrites
KingOfHypocrites

Reputation: 9537

function DoPostBack(obj) {
            __doPostBack(obj.id, 'OtherParams');
}

Just call __doPostBack

Upvotes: 1

Related Questions