asp.net触发按钮从手动回发单击服务器端

时间:2017-07-06 12:30:17

标签: javascript c# jquery asp.net jquery-confirm

我有一个asp.net页面。 &安培;我在这里使用jquery确认插件。   https://craftpip.github.io/jquery-confirm/

我希望当用户点击按钮时,会提示他们输入确认对话框&amp;当他们说确认时,只有我的按钮点击服务器才会被解雇。我不想使用public Vector2 MeasureString(string text, System.Drawing.Font font, int wrapWidth = int.MaxValue) { using(var gfx = System.Drawing.Graphics.FromImage(new System.Drawing.Bitmap(1, 1))) { var s = gfx.SmartMeasureString(text, font, wrapWidth); //SmartMeasureString is an extension method I made for System.Drawing.Graphics which applies text rendering hints and formatting rules that I need to make text rendering and measurement accurate and usable without copy-pasting the same code. return new Vector2((float)Math.Ceiling(s.Width), (float)Math.Ceiling(s.Height)); //Better to round up the values returned by SmartMeasureString - it's just easier math-wise to deal with whole numbers } } public void DrawString(string text, int x, int y, Color color, System.Drawing.Font font, int wrapWidth = 0) { x += _startx; y += _starty; //_startx and _starty are used for making sure coordinates are relative to the clip bounds of the current context Vector2 measure; if (wrapWidth == 0) measure = MeasureString(text, font); else measure = MeasureString(text, font, wrapWidth); using (var bmp = new System.Drawing.Bitmap((int)measure.X, (int)measure.Y)) { using (var gfx = System.Drawing.Graphics.FromImage(bmp)) { var textformat = new System.Drawing.StringFormat(System.Drawing.StringFormat.GenericTypographic); textformat.FormatFlags = System.Drawing.StringFormatFlags.MeasureTrailingSpaces; textformat.Trimming = System.Drawing.StringTrimming.None; textformat.FormatFlags |= System.Drawing.StringFormatFlags.NoClip; //without this, text gets cut off near the right edge of the string bounds gfx.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixel; //Anything but this and performance takes a dive. gfx.DrawString(text, font, new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(color.A, color.R, color.G, color.B)), 0, 0, textformat); } var lck = bmp.LockBits(new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); //Lock the bitmap in memory and give us the ability to extract data from it so we can load it into a Texture2D var data = new byte[Math.Abs(lck.Stride) * lck.Height]; //destination array for bitmap data, source for texture data System.Runtime.InteropServices.Marshal.Copy(lck.Scan0, data, 0, data.Length); //cool, data's in the destination array bmp.UnlockBits(lck); //Unlock the bits. We don't need 'em. using (var tex2 = new Texture2D(_graphicsDevice, bmp.Width, bmp.Height)) { for (int i = 0; i < data.Length; i += 4) { byte r = data[i]; byte b = data[i + 2]; data[i] = b; data[i + 2] = r; } //This code swaps the red and blue values of each pixel in the bitmap so that they are arranged as BGRA. If we don't do this, we get weird rendering glitches where red text is blue etc. tex2.SetData<byte>(data); //Load the data into the texture _spritebatch.Draw(tex2, new Rectangle(x, y, bmp.Width, bmp.Height), Color.White); //...and draw it! } } } 对话框。

我能够使用jquery确认&amp;通过Button的window.confirm属性手动调用回发。

ClientClick事件正在解雇。但是,按钮的服务器端的单击事件不会被触发。

我缺少什么?

ASPX代码:

__doPostBack

守则背后:(简体)

 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Tester.aspx.cs" Inherits="BLF_Gauri.Tester" %>

<html>
<head>
    <script src="Scripts/jquery-2.1.0.min.js"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.2.3/jquery-confirm.min.css">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.2.3/jquery-confirm.min.js"></script>

</head>
<body>
    <form runat="server">
        <asp:Button ID="Button2" runat="server" Text="YEs" OnClick="Button2_Click"  
OnClientClick="return TestClick(this);" />
    </form>

    <script type="text/javascript">

        function TestClick(x)
        {
            jQuery.confirm({
                title: 'Confirm!',
                content: 'Simple confirm!',
                buttons: {
                    confirm: function () {
                        __doPostBack("'" + x.id + "'", 'OnClick');
                    },
                    cancel: function () {
          //              Do Nothing
                    }
                }
            });
            return false;
        }
    </script>


</body>
</html>

1 个答案:

答案 0 :(得分:0)

所以我解决了这个问题!我没有使用__dopostback,而是使用了这个。

WebForm_DoPostBackWithOptions(
      new WebForm_PostBackOptions("" + x.name + "", "", true, "", "", false, true));

x.name coz在母版页内。 id更改。