saving image with specific name before javascript function RRS feed

  • Question

  • User186897 posted


    I have below code which convert text to imag on page load

    I want this to happen before any other javascript function..I have a javascript function function init()(in aspx page)..I want the below code to happen before function init() how do i do that?

     <asp:Label ID="Label1" runat="server" Text="1234" />
    Dim text As String = Label1.Text.Trim() Dim bitmap As New Bitmap(1, 1) Dim font As New Font("Arial", 25, FontStyle.Regular, GraphicsUnit.Pixel) Dim graphics As Graphics = Graphics.FromImage(bitmap) Dim width As Integer = CInt(graphics.MeasureString(text, font).Width) Dim height As Integer = CInt(graphics.MeasureString(text, font).Height) bitmap = New Bitmap(bitmap, New Size(width, height)) graphics = Graphics.FromImage(bitmap) graphics.Clear(Color.White) graphics.SmoothingMode = SmoothingMode.AntiAlias graphics.TextRenderingHint = TextRenderingHint.AntiAlias graphics.DrawString(text, font, New SolidBrush(Color.FromArgb(255, 0, 0)), 0, 0) graphics.Flush() graphics.Dispose() Dim fileName As String = Path.GetFileNameWithoutExtension(Path.GetRandomFileName()) & ".jpg" bitmap.Save(Server.MapPath("/imgs/12.jpg") & fileName, ImageFormat.Jpeg)

    Wednesday, November 23, 2016 12:01 PM

All replies

  • User-1838255255 posted

    Hi Lexi85,

    According to your description, as far as I know, execute JS function is after page_load event finish. For more details, you can refer to ASP.NET Page Life Cycle Overview, this article will introduce the order of event executed. For explain this, I make a sample show how to run JS and page_load!

    Here is the sample code:

    <head runat="server">
        <script src="Scripts/jquery-1.10.2.min.js"></script>
            $(function () {
     protected void Page_Load(object sender, EventArgs e)
                Label myLabel = new Label();
                myLabel.Text = "Testing";
                myLabel.ID = "Test";


    This result is show that after dynamically create a label control, then add style. If page execute JS before page load, JS will can not find the element! I hope you can understand my meaning, if this reply can not solve your problem, please let me know!

    Best Regards,

    Eric Du

    Thursday, November 24, 2016 6:40 AM