标签: code-behind

从代码隐藏中传递JavaScript函数的参数

我想从aspx控件调用一个javascript函数.例如,假设我有:

<html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
    function test(x, y)
    {

    }
</script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button ID="Button1" runat="server" Text="Button"
         onclick="Button1_Click"/>
    </div>
    </form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

并在后面的代码中:

protected void Button1_Click(object sender, EventArgs e)
{
    // do stuff (really going to a database to fill x and y)
    int[] x = new int[] { 1, 2, 3, 4, 5 };
    int[] y = new int[] { 1, 2, 3, 4, 5 };

    // call javascript function as …
Run Code Online (Sandbox Code Playgroud)

.net javascript c# asp.net code-behind

11
推荐指数
3
解决办法
10万
查看次数

如何在代码隐藏中添加GridView列?

我正在尝试在ASP.NET 2.0中向GridView添加一列

gridViewPoco.Columns.Add(...)
Run Code Online (Sandbox Code Playgroud)

但是,我找不到合适的选择.我想要以下等价物:

<asp:BoundField>
<asp:TemplateField>
Run Code Online (Sandbox Code Playgroud)

c# asp.net gridview code-behind

11
推荐指数
2
解决办法
3万
查看次数

如何从代码隐藏设置图像资源URI

我试图将PNG图形嵌入到DLL中并将其作为一个加载到Image控件BitmapImage.但是,WPF不断抛出异常,说无法找到资源.

首先,一些最小的示例代码和重现问题的步骤:

  • 使用空主窗口创建名为ImageResTest的WPF项目(可以将默认命名空间设置为ImageResTest).主窗口的代码隐藏文件应如下所示:

    using System;
    using System.Windows;
    using System.Windows.Controls;
    
    namespace ImageResTest
    {
        public partial class Window1 : Window
        {
            public Window1()
            {
                InitializeComponent();
    
                var obj = new MyData.SomeStuff.MyClass();
    
                this.Content = obj.Img;
            }
        }
    }
    
    Run Code Online (Sandbox Code Playgroud)
  • 创建一个名为ImageResTestLib的类库(您可以将默认命名空间设置为ImageResTest,如上所述,因此此处讨论的所有内容都位于相同的根命名空间中).

  • ImageResTestLib中的引用添加到PresentationCore,PresentationFramework,System.XamlWindowsBase.
  • ImageResTest中的引用添加到ImageResTestLib.
  • ImageResTestLib内,添加文件夹层次结构MyData/SomeStuff/Resources.
  • 在该SomeStuff文件夹中,添加以下文件MyClass.cs:

    using System;
    using System.Windows;
    using System.Windows.Controls; …
    Run Code Online (Sandbox Code Playgroud)

wpf resources code-behind

11
推荐指数
1
解决办法
3万
查看次数

如何在代码后面阅读WPF发布版本号

我想在启动窗口中阅读和显示WPF应用程序发布版本号,在发布选项卡中的项目属性中有发布版本,我该如何获取它并在WPF窗口中显示它.

提前致谢

c# wpf xaml code-behind

11
推荐指数
4
解决办法
2万
查看次数

从asp.net中的代码调用jquery函数似乎不起作用

我在将记录插入数据库后调用了一个jquery函数...

ScriptManager.RegisterClientScriptBlock(LbOk, typeof(LinkButton), "json",
                             "topBar('Successfully Inserted');", true);
Run Code Online (Sandbox Code Playgroud)

我已将其包含在我的母版页中,用于在回发后执行jquery函数,

<script type="text/javascript">
    function load() {
 Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
      }
    function EndRequestHandler()
       {
           topBar(message);
     }


 function topBar(message) {
    alert(a);
    var alert = $('<div id="alert">' + message + '</div>');
    $(document.body).append(alert);
    var $alert = $('#alert');
    if ($alert.length) {
        var alerttimer = window.setTimeout(function() {
            $alert.trigger('click');
        }, 5000);
        $alert.animate({ height: $alert.css('line-height') || '50px' }, 200).click(function() {
            window.clearTimeout(alerttimer);
            $alert.animate({ height: '0' }, 200);
        });
    }
}
    </script>

<body onload="load();">
Run Code Online (Sandbox Code Playgroud)

但它似乎不起作用......任何建议..

c# asp.net jquery updatepanel code-behind

10
推荐指数
1
解决办法
1万
查看次数

从WPF中的代码设置验证错误模板

我的WPF应用程序中有一个TextBox.我已经为验证错误定义了一个ControlTemplate,如下所示:

<ControlTemplate x:Key="validationTemplate">
    <DockPanel LastChildFill="True">
         <TextBlock DockPanel.Dock="Bottom"  Text="Invalid Input: "></TextBlock>
                 <AdornedElementPlaceholder />
    </DockPanel>
</ControlTemplate>
Run Code Online (Sandbox Code Playgroud)

我的TextBox如下:

<TextBox Validation.ErrorTemplate="{StaticResource validationTemplate}">                                              
    <TextBox.Text>
        <Binding Path="TEXT1" ValidatesOnDataErrors="True" validatesOnExceptions="True">
         </Binding>
    </TextBox.Text>
</TextBox>
Run Code Online (Sandbox Code Playgroud)

现在,如果我的TextBox添加了ValidationRule,然后我在那里验证,错误模板正确应用.但由于其他一些问题我无法做到这一点.

所以我必须在PreviewLostKeyboardFocus中验证TextBox的内容.我正在验证TextBox.现在我想在后面的代码中为TextBox设置错误模板,但我无法做到!!

我尝试了这个,但它并不像有意的那样工作::

private void blockTextBox_PreviewLostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
    {
        TextBox txtBox = sender as TextBox;
        txtBox.Template = this.FindResource("validationTemplate") as ControlTemplate;

        //this behaves strange; it removes the TextBox and places the ErrorTemplate. 
       //I want it to behave like the way WPF does internally wherein it places 
       //the error template around TExtBox
    }
Run Code Online (Sandbox Code Playgroud)

问题1:我想知道如何将错误模板添加到TextBox

问题2:我想知道如何从代码中设置控件模板的错误消息.例如,我想将默认错误消息"Invalid …

validation wpf textbox code-behind controltemplate

10
推荐指数
2
解决办法
1万
查看次数

以编程方式添加其他Css类

我有一个带有名为'required'的Css类的文本框.当用户单击一个按钮时,我想在文本框中添加额外的Css类,称为"错误",而不删除"必需"类.我想从代码隐藏中实现这一点.

css asp.net code-behind

10
推荐指数
2
解决办法
3万
查看次数

使用min(width,height)/ 2作为半径在WPF中绘制一个圆

如何使用min(width, height)/2半径在WPF(没有代码隐藏)中绘制圆圈?

wpf geometry xaml code-behind

10
推荐指数
2
解决办法
2万
查看次数

在后面的代码中查找类型的默认样式

在WPF中,您可以创建一个Style充当XAML中控件类型的默认值:

<Style TargetType="{x:Type local:MyControl}">
    . . .
</Style>
Run Code Online (Sandbox Code Playgroud)

然后,当WPF显示该控件时,它会Style根据其类型从资源中查找该控件.

我想在我的程序的代码隐藏中做相同的操作.我怎么找到的Style

wpf code-behind wpf-style

10
推荐指数
1
解决办法
5312
查看次数

如何使用C#检索HTML5数据 - *属性

我的表单中有一个asp复选框:

<asp:CheckBox id="option" runat="server" OnCheckedChanged="checkChange" data-attributeA="somevalue1" data-attributeB="somevalue2" AutoPostBack="true" />`
Run Code Online (Sandbox Code Playgroud)

在我的OnCheckedChanged事件中,我想要检索这两个数据属性.

protected void checkChange(object sender, EventArgs e) {}
Run Code Online (Sandbox Code Playgroud)

我怎么做?

c# asp.net html5 code-behind custom-data-attribute

10
推荐指数
1
解决办法
7972
查看次数