.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Use WebMethod in UserControl

Posted By:      Posted Date: October 03, 2010    Points: 0   Category :ASP.Net

Does anyone know if it is possible to use a WebMethod in a UserControl?

Lets say for example that I have an test.ascx file with the following method:

Imports System.Web.Services
Imports System.Web.Script.Services

    <WebMethod(), ScriptMethod()> _
    Public Sub ShowMessage()
    End Sub

In the Page_Load of the .ascx file I add some JavaScript which will do the following:

jQuery(document).ready(function() {
    $("#btnTest").click(function() {
        $.ajax( {
            type: "POST",
            url: "test.ascx/ShowMessage",
            data: "{}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",

View Complete Post

More Related Resource Links

Web Services: Extend the ASP.NET WebMethod Framework with Business Rules Validation


In an earlier article the authors showed how to build a custom WebMethods extension that provides XML Schema validation, a function that is lacking in ASP.NET. In the process they established a foundation for enforcing business rules during the deserialization of XML data. The technique, which is described in this article, uses declarative XPath assertions to test business rule compliance.In building this business rules validation engine, the authors integrate the validation descriptions into the WSDL file that is automatically generated by the WebMethod infrastructure. Finally, they demonstrate how to extend wsdl.exe, the tool that generates WebMethod proxy/server code from WSDL files, to make use of their extensions.

Aaron Skonnard and Dan Sullivan

MSDN Magazine August 2003

Web Services: Extend the ASP.NET WebMethod Framework by Adding XML Schema Validation


WebMethods make the development of XML Web Services easier by encapsulating a good deal of functionality, but there is still a lot of underlying XML processing that you have to be responsible for. For example, WebMethods do not validate messages against the implied schema. Because they are not validated, the response that's returned can result in unintended consequences. To address this, the authors extend the WebMethod framework by adding XML Schema validation through a custom SoapExtension class.

Aaron Skonnard and Dan Sullivan

MSDN Magazine July 2003

UserControl like asp:Panel


Is it possible to write own User Control with functionality like asp:Panel?

UserControl, CustomControl Design Time Support errors IOC, Dependency Injection, MVP

  Hi, is there a way to completely disable design time support for CustomControl, and UserControl ? I have about 30 UserControls and 10 CustomControls in my WinForms app, which contains some Dependency Injections and IOC stuff in constructors and Load handlers. I have lots of large UserControls containing smaller UserControls (CompositeView). All my UI code is pretty dynamic and the only thing i need to do at design time is to drag&drop containers in other containers (UserControls). And now i have a hard time doing this, because i have to wrap all constructors and Load Handlers in CurrentProccess!="devenv"... and when I'm Implementing some new View interface (which consist lots of properties) in UserControl all those properties by default throw NotImplementedException and i don't always need to implement them immediately but still i need to be able to run this code for testing. Besides, then i have to clean up designer generated class because it adds unnecessary null value property initializations, and then it way add some other ____ code, and so on.... Imagine UserControl with 10-15 nested UserControls, and then i try to open it in Form Designer and get ObjectReference NULL exception (for IOC) or some NotSupported NotImplemented exceptions (for properties) without adequate CallStack available! There is a CallStack but there is no trace in it to my Code (

How to load a usercontrol xaml at runtime ???????

Hi, I have a usercontrol xaml created in Expression Blend. Similarly i have xaml for other usercontrols as well. Now i want to draw these controls at runtime on click of buttons, the way it works in VS IDE (Toolbox and Drawing area) Is there any way to load such usercontrols on Canvas at runtime ? What would be the best way to load controls at runtime ?      Programmer

Using an Application Resource in Nested UserControl

Hello This problem has been niggling me for months and I just can't seem to get to the bottom of it. I have a UserControl, let's call it 'UC_List', and the ListBox in it uses a Style which I have declared in my Application.xaml file. When working with UC_List.xaml everything seems fine. I then place 'UC_List' into a UserControl, let's call it 'UC_Summary'. I have declared the namespace at the top of UC_Summary.xaml. The xaml code in UC_Summary now has an Error: Could not create an instance of type 'UC_Summary'. Now I cannot see anything in the Design window, only a warning saying 'Problem Loading, the document contains errors that must be fixed...' However when I run the application everything works fine! After a lot of trial and error I found that the cause of the problem seems to be the Style referenced in the Application.xaml. If I declare the Style in UserControl.Resources at the top of UC_List the error goes away and the graphics in UC_Summary return. I've so far duplicated my Styles into individual UserControls to work around the problem but this could easily lead to inconsistancies. If anyone can suggest anything I would be really pleased to try it. Thank you. Regards Chris

Property of a base UserControl it's not handled correctly

Hello,I have a class that is a base class for my server controls. Inside this class I have a property that can take values from an enumeration.public enum PanelModeEnum { Add = 1, Edit = 2, ReadOnly = 3 } public class BaseControl : System.Web.UI.UserControl { #region Event Handling Management #endregion public PanelModeEnum PanelMode { get; set; } public virtual void ChangePanelMode(PanelModeEnum newMode) { this.PanelMode = newMode; } } I have then several user controls that inherits from this BaseControl and that I add into aspx pages declaratively<gsl:PhoneNumberUC ID="ucPhoneDetail" runat="server" PhoneNumberType="Home" />I would like to show one the derived BaseControl classes inside a ModalPopupExtender using server-side code. Before doing this I call the ChangePanelMode with a value from the PanelModeEnumucPhoneDetail.PhoneNumberType = ptype; ucPhoneDetail.ChangePanelMode(PanelModeEnum.Add); this.mpePopupPhone.Show(); But when, inside the inherited user control I check for the PanelMode property likeif (this.PanelMode == PanelModeEnum.Add) { ... } the value of this.PanelMode is always equal to zero. Why?Kindly regards

Detect Deactivation of Usercontrol

Hi All, I have added a popup type usercontrol to a form which I call like this: MyUserControl = New AdvancedControl MyUserControl.StartPosition = FormStartPosition.Manual MyUserControl.TopLevel = False MyUserControl.Location = Me.Parent.PointToScreen(New Point(Me.Left, Me.Bottom)) ParentForm.Controls.Add(MyUserControl) MyUserControl.Show()  How can I detect when a user clicks somewhere other than the usercontrol and then dispose of the usercontrol.  The lost focus and deactivate events dont seem to fire. Thanks

JQuery and WebMethod asp.net validations

i am using jquery and passing my data to webmethod,but asp.net validation are not performing their desired action on button click,if i enter wrong data,they still post the data,how i m going to stop that??? 

usercontrol used in datagridviewcell

Dear Programmers, Im trying to create a user control above to be used inside a datagridviewcell this user control, has a button and a textbox. Used for lookup it loads a form the user choose the row and the record id or primary key is loaded to the uercontrol textbox. the variables are now private static, but when i have 2 usercontrols in the same datagridview, the values are the same. And when i change the properties variable from static to nonstatic public variables. the variable values are not seen and the control dont work. I will upload the classes below. I appreciate your help.<pre lang="x-c#"> namespace x { public class DataGridViewButtonTextBoxColumn : DataGridViewColumn { public DataGridViewButtonTextBoxColumn() : base(new DataGridViewButtonTextBoxCell()) { //base.DefaultHeaderCellType = typeof(DataGridViewTextBoxCell); //base.SortMode = DataGridViewColumnSortMode.Programmatic; } public override object Clone() { DataGridViewButtonTextBoxColumn Column = (DataGridViewButtonTextBoxColumn)base.Clone(); Column.DBName = this.DBName; Column.ComboLup = this.ComboLup; Column.PrimaryKeyField = this.PrimaryKeyField; Column.PrimaryKeyField2 = this.PrimaryKeyField2; return Column; } public override DataGridViewCell CellTemplate { get { return

Nested controls in UserControl return null (FindControl)

Hi everyone, I have a very weird issue. I have a UserControl that has some controls inside. I want to refer those controls after, in another postback. But when I try to get them the ".Controls" property of my controls returns null. I'm working on vs2008 Here is the sample code: public partial class MyUserControl : System.Web.UI.UserControl { protected void Page_Load(object sender, EventArgs e) { foreach (Control control in this.Controls) { Response.Write(control.ClientID); } } private void MyTable() { Table table = new Table(); TableRow row = new TableRow(); TableCell cell = new TableCell(); CheckBox check = new CheckBox(); check.ID = "theId"; check.Text = "My Check"; check.AutoPostBack = true; cell.Controls.Add(check); row.Cells.Add(cell); check = new CheckBox(); check.ID = "theOther"; check.AutoPostBack = true; check.Text = "My Other Check"; cell = new TableCell(); cell.Controls.Add(check); row.Cells.Add(cell); table.Rows.Add(row); this.Controls.Add(table); } protected override void Render(HtmlTextWriter writer) { MyTable(); base.Render(writer); } } And in the Default.aspx is like:<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.cs" Inherits="Tester.Default" %> &

UserControl with a control property?

Hi... I have defined a UserControl wich needs to reference another control like this: <ctrl:Cook TheList="listView1" DefaultFileName="MyRecipe"></ctrl:Cook> The code behind of the control has the property defined:         public ListView TheList { get; set; } But I have a runtime error saying: 'ListView' type does not have a public TypeConverter class. And in design time I get: Property TheList of type ListView cannot be specified as string.   I know WPF is trying to read a string instead of a ListView, but dont know the magic solution. Maybe a converter? Please suggest the simpler solution you can, because this is not a vital requirement on the app. Thanks in advance for any help  

How to set Panel.Zindex value though XAML code if any of the Grid/UserControl children having the fo

Hi, I have a Grid with 10 buttons. If any of these buttons has focus then I want to set the Panel.Zindex = 999 for the Grid. How to do this in XAML code?Please remember to click "Mark as Answer" on the post that helps you, and to click "Unmark as Answer" if a marked post does not actually answer your question. This will help other members to find the solution easily.

Usercontrol, in master page, calling a method on the main page?

I have user control called 'Header.asxc' that is registered in my master page. That user control has an image link. The clicking of this link needs to cause a dropdown on the main page to repopulate. I am comforable with delegatges, with populating the dropdown etc... My problem is I cant find the usercontrol from the page, in order to set the function event. I got this work previously when the user control was registered on the page in question but this case with the master page  has me confused. Here is a summary of the set up. 1. I put this in the Header.ascx usercontrol that is registered by the Master page. public Delegate locReloadCompanyDropdown;2. Further down in that page in the relevent _Click event, I put this. locReloadCompanyDropdown.DynamicInvoke();3. Back in the main page I declared these.. public delegate void reloadCompanies(); private event reloadCompanies doReloadCompanies;4. Finally I try to set the delegate doReloadCompanies += new reloadCompanies(PopulateCompanyDropdown); //Page.Header.locReloadCompanyDropdown = doReloadCompanies; //Header.locReloadCompanyDropdown = doReloadCompanies;You can see a couple of attempts I have made remarked out in the code above. Neither work. What am I missing here? Thanks all.  

UserControl content generated from XML?

I am trying to generate items in wrappanel defined in XML. I am missing something here. I got to the point where I can generate content from xml but it is duplicated. With the code below, I am getting 3 stackpanels with the same content. How to pass the the other two Person nodes from XML? Thank you in advance. XML: <?xml version="1.0" encoding="utf-8"?> <persons xmlns=""> <Person> <FirstName>AAAA</FirstName> <LastName>AAAA</LastName> </Person> <Person> <FirstName>BBBB</FirstName> <LastName>BBBB</LastName> </Person> <Person> <FirstName>CCCC</FirstName> <LastName>CCCC</LastName> </Person> </persons> <p style="margin:0in 0in 10pt"> </p>  XAML: <Window.Resources> <XmlDataProvider x:Key="DashboardData" XPath="/" Source="Data/Dashboard_DataSource.xml" /> </Window.Resources> <Grid x:Name="LayoutRoot"> <UserControl> <!-- local:UserControlWP/ --> <ItemsControl x:Name="list" ItemsSource="{Binding Source={StaticResource DashboardData}, XPath=persons/Person}"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <

Is it possible to put usercontrol in a menuitem?

I have a calendar usercontrol that I would like to put as a subitem of a menuitem. Is this possible? A c# example would be helpful if anyone knows the answer to this.   Thanks!
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend