Menu
  • HOME
  • TAGS

Visual Studio 2013 Single-File Mode?

asp.net,visual-studio-2013,code-behind

This option is only available for websites not web applications, go to File->New->Website and create a new website, then you can choose to have the code behind on the same page or separate page when you are adding new pages. Keep in mind there are differences between a website and...

asp:Button - onclick event fires code on a different code-behind?

asp.net,code-behind,site.master

Yes there is a way to do this. You need to set UseSubmitBehavior button property to false and then you can access the control that causes the post back using Request.Params.Get("__EVENTTARGET"); So the code would look like this: Button definition in Site.Master markup: <asp:Button ID="MyButton" runat="server" Text="Button" UseSubmitBehavior="false" /> code...

RDLC export directly in PDF code behind?

c#,rdlc,code-behind,export-to-pdf

Try this. protected void showReport(string fileName) { Warning[] warnings; string[] streamIds; string mimeType = string.Empty; string encoding = string.Empty; string extension = string.Empty; DataTable DataTable1 = new DataTable report.LocalReport.Refresh(); report.Reset(); report.LocalReport.EnableExternalImages = true; this.report.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Local; ReportDataSource rds2 = new ReportDataSource("DataSet1", DataTable1); report.LocalReport.DataSources.Add(rds2);...

MVVM Handling PasswordBox from codebehind

mvvm,code-behind,datacontext,passwordbox

Yes it can be handled in many ways. There is nothing wrong with code-behind. Your current solution has the problem that you're tying concrete viewmodel with PasswordBox which makes it NON reusable for other viewmodels. Better way is to write attached property with event listeners. There are many resources that...

How do I execute an event when a label is clicked?

c#,wpf,event-handling,label,code-behind

If I understand this correctly, you want a Label with a LeftMouseDown-event, which you would write from code? In that case: TestLabel.MouseLeftButtonDown += new MouseButtonEventHandler(TARGET); ...

problems with spaces when assigning url values in code-behind background-images in asp.net

asp.net,background-image,code-behind,spaces,datareader

You can use Uri.EscapeDataString() Uri.EscapeDataString(drVideo["imageName"].ToString()) This will replace space with %20...

How to stop vb code execution after calling javascript alert box using RegisterStartupScript

javascript,asp.net,vb.net,code-behind

The problem here is that Javascript is executed in the browser on the client-side, not on the server. This means that by the time the Javascript runs, the VB on the server is already completely finished executing. Your best option is to find a way to check the value while...

Calling a C# method from javascript

javascript,c#,asp.net,ajax,code-behind

Assuming your GetAccount method can be reached at /Account/GetAccount when your application runs, you could use the following: $.ajax({ type: 'GET', url: '/Account/GetAccount', data: { 'username' : 'a-username' }, dataType: 'json', success: function(jsonData) { alert(jsonData); }, error: function() { alert('error'); } }); Note - this is dependant on jQuery. This...

Change Lineseries thickness in WPFToolkit.Chart C#

wpf,charts,code-behind,lineseries

Have you tried adding a Style for the serie's Polyline instead? It seams the style for the LineDataPoint is actually for every point on the serie. Here is a working sample of a chart fully created on code-behind. You just have to create a window named MainWindow and add a...

Asp.net click event code appears in aspx page instead of code behind

c#,asp.net,visual-studio-2010,code-behind

Look in the header of the .aspx file. There should be a property named CodeBehind which references to your code file. Is something as CodeBehind="yourfile.aspx.cs" If this property is not present, the C# code is placed inside script tags in your aspx. If this property is present, references the cs...

How to set code-behind path after moving an .aspx file to a new folder?

c#,asp.net,code-behind

Physically moving ASPX/ASCX files is not enough for them to work again. You need to also update the corresponding file's page/control directive. You have to change the CodeBehind value of the @Page directive to reflect the new path. Your ASPX page probably has something like this: <%@Page CodeBehind="~/Master/Employee.aspx.cs" ... %>...

Control not found in the code behind of an aspx page

c#,asp.net,.net,master-pages,code-behind

I think you should be using var txt1 = Content1.FindControl("TextBox1") and then if the txt1 is not null use it as you would normally use TextBox1 ? var txt1 = Content1.FindControl("TextBox1"); txt1.Text = "some value"; ...

How can I read WPF publish version number in code behind

c#,wpf,xaml,code-behind

Add reference to System.Deployment library to your project and adjust this snippet to your code: using System.Deployment.Application; and string version = null; try { //// get deployment version version = ApplicationDeployment.CurrentDeployment.CurrentVersion.ToString(); } catch (InvalidDeploymentException) { //// you cannot read publish version when app isn't installed //// (e.g. during debug) version...

C# Find Control

c#,asp.net,code-behind

Unfortunately, FindControl doesn't find nested controls. From MSDN: This method will find a control only if the control is directly contained by the specified container; that is, the method does not search throughout a hierarchy of controls within controls. Example: <asp:Panel ID="pnl" runat="server"> <asp:Label ID="lbl" runat="server" Text="I'm here!" /> </asp:Panel>...

Restore original selection in datagrid after calling SelectAllCells()

wpf,datagrid,code-behind

It's a little fiddly, but it can be done. The basic premise is to take a note of what you have selected before you select everything; and then reselect those records after the copy. Not the ToList() after the Distinct() is important. It will not work without this because of...

How to get Page.UICulture in a static WebMethod?

c#,asp.net,.net,code-behind,webmethod

Simply, you can't. The property Page is not available to a static method, and that makes sense, since in the context of that static WebMethod, you don't have a page. You could save the relevant properties in a Session variable and get it from the session info in your WebMethod....

How to display data into tag using datatable?

c#,asp.net,datatable,code-behind

Use data controls especially GridView. Add following markup in .aspx page <asp:GridView runat="Server" id="data"/> Code in click handler. protected void Button1_Click(object sender, EventArgs e) { MSConnector connector = new MSConnector(); connector.ConnectionString = "SERVER=xbetasql,52292;UID=username;Password=secret;DATABASE=ATDBSQL;"; DataSet selectedAngels = connector.ExecuteQuery("select * from customer where idcustomer = 453433"); DataTable dt = selectedAngels.Tables[0]; data.DataSource =...

How can I make controls added to existing mark-up be automatically hooked up to the code behind?

c#,asp.net,code-behind

If it's a web application your aspx pages should have a designer file by default. But, if your project is a website then .aspx pages will not have a designer file and each page is compiled on the fly by VS compiler. there are few files being created by VS...

Web Form code behind not creating Partial Class, page inherits “ProjectName.ClassName” instead of just “ClassName”. Visual Studio 2013

asp.net,inheritance,webforms,code-behind,web-application-project

When you create a new Web Forms page from a Web Application project, it will create the page as described in the question. In order to get it the right way, the Web Form page needs to be made in a Web Site project. This page can then be used...

ASP.net: insert statement and gridview

c#,asp.net,gridview,code-behind,sql-insert

Problem 1: Not very sure but I think you are missing single quotes when you are adding txtAddress and txt_id to the query. Your query string query1 = "insert into tbl2(id,name,address) values (" + txt_id.Text + ",'" + txt_name.Text + "'," + txt_address.Text + ")"; Should be changed to string...

Changing the ContentStringFormat property of a Label in code behind

c#,wpf,label,code-behind

Maybe not very elegant, but this works: var content = MyLabel.Content; MyLabel.Content = null; MyLabel.ContentStringFormat = "Bye {0}"; MyLabel.Content = content; ...

Adding click event to generated MenuItems with datatemplate in WPF

c#,wpf,event-handling,click,code-behind

You're only handling the click on the "header" MenuItem here. Put the click handler into a Style inside the MenuItem's ItemContainerStyle. <MenuItem> <MenuItem.ItemContainerStyle> <Style TargetType="{x:Type MenuItem}"> <EventSetter Event="Click" Handler="PolygonShapesMenu_OnClick"/> </Style> </MenuItem.Resources> </MenuItem> The clicked sub MenuItem will then be the sender....

How can i set selected item property from the list using code behind?

c#,list,code-behind,selected,listitem

Are you using ASP.net? if so you can use asp control... DropDownList (instead of simple select) If you can't, try something like this: add runat="server" to myGroupList on .aspx file. then on .cs file: for (int i = 0; i < myGroupList.Items.Count; i++) { if (element.Children[i].InnerText == "abc_group") { element.SetAttribute("selected",...

Declare a single static variable that will be used by many WebMethod functions

c#,asp.net,session-variables,code-behind,webmethod

Currently you're initializing the variable once, when the class is first loaded. You want to have a different value on each request. Rather than having a variable for that, you should have a property or method. For example: private static string Service { get { return (string) HttpContext.Current.Session["ucService"]; } }...

Specify .XAML part of UserControl in code-behind

c#,wpf,xaml,code-behind

I found solution appropriate for me. This it the way how to define Style of TreeViewItem in code, not in XAML. Now I have TreeView definded only in code-behind, therefore, error will not be risen. public class MyTreeView : TreeView { public event RoutedEventHandler ItemLostLogicFocus; protected override void OnInitialized(EventArgs e)...

ASP.NET C# Select partial text from textbox pressing a button

c#,javascript,asp.net,textbox,code-behind

Here is the solution Javascript function wraptext() { var SelectionStart = document.getElementById("text").selectionStart; var SelectionEnd = document.getElementById("text").selectionEnd; var OldVal = document.getElementById("text").value; var NewVal = OldVal.substring(0, SelectionStart) + " bla " + OldVal.substring(SelectionStart, SelectionEnd) + " bla " + OldVal.substring(SelectionEnd, OldVal.length); document.getElementById("text").value = NewVal; } Html <input type="text" id="text" value="123456" /> <input...

Using Selenium and ASPX.net, how to pass a Mock to codebehind?

asp.net,selenium,mocking,moq,code-behind

Background Usually, Moq is used during Unit Testing (i.e. one single class or system layer under test), whereas Selenium would imply browser automation testing and your Selenium Unit Test would be out of process of your WebForm. One primary benefit of a mock is that it offers the ability to...

How to add asp:TextBox dynamically on code behind ? (Not TextArea)

c#,asp.net,visual-studio-2012,visual-studio-2013,code-behind

The problem with creating the controls programatic is that you need to make sure that you create them every postback. With that said the easier and more solid way would be to use a repeater. Then you can repeat the number of textboxes depending on the number of accounts. Like...

wpf binding in xmas updated but not in code behind

wpf,data-binding,code-behind

The Source of a binding is the object hosting the property, not the property itself. You want: Analyzer.Graph.SetBinding(ListView.ItemsSourceProperty, new Binding("ItemsData") { Source = MyViewModel.MyData }); However, since you already have an "ItemsData" property that notifies when it changes, then just change that rather than the binding. Bindings are just a...

Generating an aspx
content from C# code behind

c#,html,asp.net,c#-4.0,code-behind

So you want to repeat following 67 times: <div style="width: 100%; text-align:justify"> <div style="float: left; width: 70%; align-items: center; background-color:rgba(99, 99, 99, 0.40); padding-top: 5px;padding-left: 5px;padding-bottom: 5px;padding-right: 5px;"> <asp:Label ID="LabelM12" runat="server"></asp:Label> </div> <div style="float: left; width: 25%; text-align:center; align-items:center"> <asp:RadioButtonList ID="RadioButtonListM12" runat="server" RepeatDirection="Horizontal"...

How to retrieve HTML5 data-* Attributes using C#

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

The same approach in the link shared by @musefan will work for you. I have created a CheckBox: <asp:CheckBox ID="CheckBox1" runat="server" OnCheckedChanged="CheckBox1_CheckedChanged" dataAttributeA="Test Custom Attr A" dataAttributeB="Test Custom B" Text="Check it or dont" AutoPostBack="True" /> Then a method to handle the changed event: protected void CheckBox1_CheckedChanged(object sender, EventArgs e) {...

How to create a link to a website in vb code behind?

asp.net,vb.net,url,code-behind

Use Response.Redirect if you want to send the current page to a new url: Protected Sub Menu1_MenuItemClick(sender As Object, e As MenuEventArgs) Handles Menu1.MenuItemClick If e.Item.Text = "SomeItem" Then Response.Redirect("http://www.stackoverflow.com") End If End Sub To open a new url in a new window/tab you would have to use javascript. Normally...

how to enable a control like dropdownlist which is inside a panel that is disabled

c#,asp.net,code-behind

You cannot enable a single control in a container control that is disabled because that property is inherited (in the same manner as Visible). So the only way is to enable the Panel and this control but disable all other controls in the panel. dropdownlist.Enabled = true; testpanel.Enabled = dropdownlist.Enabled;...

How can i refresh a asp page from code behind? C# [duplicate]

c#,asp.net,timer,reload,code-behind

I recommend you to use Ajax to perform this operation. But a simple way to achieve that is using Asp.Net Timer and Update Panel components. In .aspx: <asp:ScriptManager runat="server" id="ScriptManager1"/> <asp:UpdatePanel runat="server" id="UpdatePanel1"> <ContentTemplate> <asp:Timer runat="server" id="Timer1" Interval="10000" OnTick="Timer1_Tick"> </asp:Timer> <asp:Label runat="server" Text="Page not refreshed yet." id="Label1"> </asp:Label> </ContentTemplate> </asp:UpdatePanel>...

How to call code behind function from label.text in asp.net

c#,asp.net,eval,code-behind

Unless you're using a template based control (such as <asp:Repeater> or <asp:GridView>) then you can't use inline code-blocks such as you have within a server-side control. In other words, you can't have <%=%> blocks within the attributes of server-side controls (such as <asp:Label>). The code will not be run and...

How to check if words start with a hashtag in a Label then do something

c#,asp.net,code-behind

You can use StartsWith method if(s.StartsWith("#")) Alternatively you can also check for the first char: if(s[0] == '#') This is prone to error is s is an empty string.You can use RemoveEmptyEntries option in your Split method to avoid this....

xmldataprovider using element values in code behind

c#,xml,wpf,code-behind,xmldataprovider

I believe I have finally found the answer that avoids the use of a hidden control. First off many thanks to kennyzx for his answer which while it still used a hidden control was invaluable in leading me to this answer. Instead of putting the XmlDataProvider in the Grid.Context it...

Binded List Box only viewing the last item

c#,wpf,html-agility-pack,observablecollection,code-behind

On your code you do overwrite your properties (Artist, Duration, etc ...) so obviously you will only see the last song that the foreach loop processed. Solution: Use a collection that you will fill in the loop by creating a new Song from each node in your HTMLNodeCollection Example: Code...

Is this bad MVVM practice? [closed]

c#,wpf,mvvm,viewmodel,code-behind

Yes it is bad practice, because you are directly referencing the ViewModel from the View which implies a dependency between the View and the ViewModel and thus tight coupling. The pattern specifically calls for the View NOT to be dependent on a specific ViewModel instance or type. The idea here...

Button with codebehind

c#,wpf,code-behind

Are you asking for the C# code equivalent of that XAML? If so, it would look like this: Button b = new Button(); b.Content = "Table 1"; Grid.SetColumn(b, 1); b.Click += button_Click; b.CommandParameter = 1; b.HorizontalAlignment = HorizontalAlignment.Left; b.Margin = new Thickness(34, 31, 0, 0); Grid.SetRowSpan(b, 2); b.VerticalAlignment = VerticalAlignment.Top;...

How to trigger jquery function, after inserting html table from code behind?

jquery,asp.net,jquery-datatables,code-behind

You could try to execute a "named" javascript function from code behind using "Page.ClientScript.RegisterStartupScript" Method Code behind (I use C#): Page.ClientScript.RegisterStartupScript(this.GetType(), "table_function", "functionName();", true); Javascript: function functionName(){ $('#MyTable').dataTable({ "bPaginate": true, "bLengthChange": true, "bFilter": true, "bSort": true, "bInfo": true, "bAutoWidth": true }); } Hope this helps. Let me know if it...

.net 4.5 web forms c# Context of a variable isn't found in Codefile

.net,webforms,code-behind,saml-2.0

Solution: Killed the entire aspx page. created a new one through the studio tools, then merged the aspx and cs files together. Still not sure what went wrong (inheritance linking incorrectly, etc..) but code is now compiling.. Now to add the logging functionality as described above, and then actually add...

Xamarin Can't Access Controls on Code Behind

c#,.net,xamarin,code-behind,xamarin.forms

The latest update seemed to fix the issue.

How to change default mouse hover behavior on dynamically generated buttons

c#,wpf,code-behind,dynamically-generated,mousehover

This is happening because the default Button control style has a trigger that changes the Background property of the button when the mouse hovers over it. You need to use a custom style for the button: <Style x:Key="MySuperButtonStyle" TargetType="{x:Type Button}"> <Setter Property="OverridesDefaultStyle" Value="True" /> <Setter Property="Width" Value="50" /> <Setter Property="Height"...

WPF. Change DataContext on event binding to access code-behind on a MVVM project

wpf,mvvm,code-behind,datacontext

Validation.Error is an event, not a property. You can't set Bindings to events. You can use things like MVVM Light's EventToCommand, or Microsoft's own Interactivity EventTrigger to associate Commands to Events. But there really isn't anything wrong with just adding a regular event handler in code-behind and calling some viewmodel...

Ajax connection with asp.net codebehind and runtime compilation trouble

asp.net,ajax,vb.net,code-behind,runtime-compilation

Now i understand that this might not be the most efficient method, or necessarily the industry standard and correct method, but it works for my small use edge case where data security is not much of a concern. As it turn's out i wasn't too far off the mark but...

Dangerous query string, yet it has not changed?

c#,asp.net,webforms,query-string,code-behind

add this line to your web.config if it's not there: <system.web> <httpRuntime requestValidationMode="2.0" /> </system.web> then on that particular aspx page set this property in your page tag like below: <%@ Page ValidateRequest="false" however this is against your page's security....

Getting selected items from a listbox using the index instead of value

c#,listbox,code-behind

For #2 you want single quotes around each value, not double quotes. (Assuming Hobbies is not an integer in the DB) string strHobbies = String.Join("','", selectedHobbies).TrimEnd(); ...

How can I access the binding properties of a XAML object, from my code behind?

c#,wpf,xaml,data-binding,code-behind

You can access from your code behind using below code. BindingExpression be= txt.GetBindingExpression(TextBox.TextProperty); string format=be.ParentBinding.StringFormat; ...

Is there a way to let an asp.net page “catch up” to itself?

c#,asp.net,code-behind

OnClick is a server-side event of the Button. So you cannot write: OnClick="this.disabled=true; btnSubmit_Click" OnClick accepts only the method-name of the server-side event handler. If you want to handle the client-side button-click event to prevent that the user can click on it multiple times use OnCLientClick: OnCLientClick = "this.disabled=true;" You...

format DataGridTextColumn from code-behind

c#,wpf,code-behind,string.format,datagridtextcolumn

You can solve your problem by creating a style rather than formating the text in the cell. first, create a style: Style style = new Style(typeof(DataGridCell)); style.Setters.Add(new Setter(HorizontalAlignmentProperty, HorizontalAlignment.Right)); than assign the style to the column textC.CellStyle = style; ...

Binding wpf object property to class property - usual way doesnt work for me

c#,wpf,xaml,binding,code-behind

Given a ConfigVM class like public class ConfigVM { public string Name { get; set; } } and perhaps a main view model like public class MainVM { public ObservableCollection<ConfigVM> ConfigItems { get; set; } } you may easily create an ItemsControl in XAML like this: <ItemsControl ItemsSource="{Binding ConfigItems}"> <ItemsControl.ItemTemplate>...

In WPF code-behind, how do I set the background color for each individual ListBoxItem where the color is based on the item itself?

wpf,colors,background,code-behind,listboxitem

The problem with your code is that you assign the same property ItemsContainerStyle that impacts all of the ListBoxItems. So all of the items will have the color of the last one. Your code should directly assign the Background of the items. for (int i = 0; i < ListBox_SavedColors.Items.Count;...