I have a user control on a Web Site with this inside.
Namespace MenuTreePanel
Public Class MenuTreePanel
Inherits System.Web.UI.UserControl
Public root As New MenuNode(0, 0, "root", "")
Public WithEvents Spany1 As HtmlGenericControl = New HtmlGenericControl("UL")
Public WithEvents Spany2 As HtmlGenericControl = New HtmlGenericControl("UL")
Public WithEvents Spany3 As HtmlGenericControl = New HtmlGenericControl("UL")
Public Function getRoot() As MenuNode
Return root
End Function
End Class
End Namespace
When I go to access the getRoot function I get Error
'getRoot' is not a member of 'ASP.MenuTreePanel'.
The namespace is incorrectly labelled as ASP, and I was wondering where that might be coming from. In the object explorer, my control is listed under both the correct namespace and the ASP namespace.
Referenced on the page using
<%# Register TagPrefix="MenuTreePanel" Src="~/MenuTreePanel.ascx" TagName="MenuTree" %>
<MenuTreePanel:MenuTree ID="menuTreeSelect" runat="server"></MenuTreePanel:MenuTree>
Edit 2:
<%# Control Language="vb" CodeBehind="~/MenuTreePanel.ascx.vb"className="MenuTreePanel" %>
and the attempt to access it
Dim root As New MenuNode(0, 0, "root", "")
root = (menuTreeSelect).getRoot()
The problem is likely that you're attempting to access the property statically. My assumption is that you do not want to access it statically, since it's a control.
My suggestion is that you look at how you're using the MenuTreePanel object.
You should be accessing it like this:
menuTreeSelect.getRoot();
and not like this:
MenuTreePanel.getRoot();
Try:
Public Shared Function getRoot() As MenuNode
Return root
End Function
I wasn't linking the CodeFile and the ASCX correctly with a Web Site.
I had to change CodeBehind to CodeFile and add an inherits, and now everything is working correctly.
Thanks for your help.
I am building a custom control with client side scripts that I would like to reference using ScriptManager.ScriptResourceMapping (to make use of the Path and DebugPath attributes).
I would like the custom control to be easily ported to other projects - i.e. I would like to drag and drop the codebehind files (and eventually make the control a separate DLL, but for now the drag and drop will suffice). I would therefore like to avoid (1) having the client script as an embedded resource, (2) referenced as a WebResource in the AssemblyInfo, or (3) have the ScriptManager.ScriptResourceMapping.AddDefinition in global.asax.
In simple terms can I get the script management code to be in just the custom control's code?
At the moment I am getting an error stating that the script reference cannot be found in the assembly, and I guess I am setting the wrong assembly.
My custom control code is as follows:
Public Class MyControl
Inherits System.Web.UI.LiteralControl
Implements ISectionControl, IScriptControl
Private _scriptReference As ScriptReference
Public Sub New()
' Add the resource mapping
ScriptManager.ScriptResourceMapping.AddDefinition("MyControlScript", New ScriptResourceDefinition With {
.ResourceAssembly = System.Reflection.Assembly.GetExecutingAssembly,
.ResourceName = "MyControlScript.js",
.Path = "Path.To.MyControlScript.minimised.js",
.DebugPath = "Path.To.MyControlScript.original.js"
})
' Set the script reference
_scriptReference = New ScriptReference("MyControlScript.js", Assembly.GetExecutingAssembly.FullName)
End Sub
Protected Overrides Sub OnPreRender(e As System.EventArgs)
MyBase.OnPreRender(e)
' Register the script
ScriptManager.GetCurrent(Page).RegisterScriptControl(Of MyControl)(Me)
' Some code to set the Text of the literal control
' ...
End Sub
Public Function GetScriptDescriptors() As System.Collections.Generic.IEnumerable(Of System.Web.UI.ScriptDescriptor) Implements System.Web.UI.IScriptControl.GetScriptDescriptors
Return New ScriptDescriptor() {}
End Function
Public Function GetScriptReferences() As System.Collections.Generic.IEnumerable(Of System.Web.UI.ScriptReference) Implements System.Web.UI.IScriptControl.GetScriptReferences
Return New ScriptReference() {_scriptReference}
End Function
End Class
I hope the question makes sense. Thanks for taking the time to read through.
Ali
Answered this myself, I was getting confused with the assemblies and the constructors for ScriptReference. I just wanted a ScriptReference with the (mapped) name so I used the blank constructor and then set Name. I could then remove the assembly information.
Adjusting the following sorted the problem out:
Public Sub New()
' Add the resource mapping
ScriptManager.ScriptResourceMapping.AddDefinition("MyControlScript", New ScriptResourceDefinition With {
.Path = "Path.To.MyControlScript.minimised.js",
.DebugPath = "Path.To.MyControlScript.original.js"
})
' Set the script reference
_scriptReference = New ScriptReference() With {.Name="MyControlScript"}
End Sub
I'm working on a form that uses CA service desk web service request system, but am having trouble finding any assistance or coding examples for the service with asp.net and visual basic. I contacted their technical support, but no one on their staff has experience using it. Do you know where I could get help?
Just finished doing a vb.net webservice to CA service desk. Hopefully some of the code below can be used in your project.
Imports System.Xml
Imports Microsoft.Web.Services3
Imports Microsoft.Web.Services3.Messaging
Imports Microsoft.Web.Services3.Addressing
Partial Class _Default
Inherits System.Web.UI.Page
Dim ws1 As New USD_WebService.USD_WebService
Public sid As Integer
Public userhandle, username, password As String
Public summary, description, incident, MH, SUN As String
Public group, category, uammsg, handle As String
Dim attrVal(5), attr(1), prop(1) As String
Public requestHandle, requestNumber As String
Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
ws1.Url = "http://"YOUR SERVER":8080/axis/services/USD_R11_WebService?wsdl"
'Get the Field values for the ticket (Could be done connecting to LDAP server)
username = userid1.Value 'Name from form field
password = pass1.Value 'Windows Password from form field
summary = Summary1.Value 'Summary from form field
description = desc1.Value 'Description from form field
'Get the SID from the CA Server
sid = ws1.login(username, password)
If (sid <= 0) Then
Response.Write("login failed")
Else
Response.Write("login succeeded")
End If
'Get the User ID from the CA Server
userhandle = ws1.getHandleForUserid(sid, username)
'Set the Field values to create the ticket.
'The AttrVal must be in pairs or the call will fail
'e.g. header & header details
attrVal = New String() {"customer", userhandle, "category", category, "group", group, "description", description, "summary", summary, "ZReporting_Method", "400001", "impact", "5", "type", "R"}
prop = New String() {""}
attr = New String() {"persistent_id"}
'Returned data from the CA server
requestHandle = ""
requestNumber = ""
'Send the request with the details from the form
ws1.createRequest(sid, userhandle, attrVal, prop, "", attr, requestHandle, requestNumber)
Response.Write("Ticket Number: " + requestNumber + " Created Successfully.")
'MsgBox("Ticket Number: " + requestNumber + " Created Successfully.")
MsgBox(requestHandle, 3)
'Log off the server using the SID
ws1.logout(sid)
Just remember, the attributes need to be in pairs, Label & Label Data e.g."SUMMARY" & "Summary text". You will need to import the CA WebService into the project. I'm using MS Visual Web Developer 2008 Express to create my project.
I don't use VB.net actual but this is C# code that might help you understand how you can access to CA web-service and perform select quires directly to it. you can translate to VB.net it works the same way
You can find how to use web service as pdf here
and
You can find CA Reference to web-service here it contains description on all objects you might need
webServiceName.USD_WebService wsUSD = new webServiceName.USD_WebService();
string username = "user1" , password = "password";
int sid = 0;
string userhandle = null;
XmlDocument xDoc = new XmlDocument();
sid = wsUSD.login(username, password);
userhandle = wsUSD.getHandleForUserid(sid, username);
string userEmailID = "myMail#company.com";
string[] attrs = new string[7];
attrs[0] = "type.sym";
attrs[1] = "ref_num";
attrs[2] = "open_date";
attrs[3] = "description";
attrs[4] = "status.sym";
attrs[5] = "last_mod_dt";
attrs[6] = "persistent_id";
//here is the important part
//note: 'CL' means closed
//where the cr is Object ref to SQL database
xDoc.LoadXml(wsUSD.doSelect(sid, "cr", " customer.email_address = '" + userEmailID + "' AND status != 'CL'", -1, attrs));
//here is other queries you can use the same way
xDoc.LoadXml(wsUSD.doSelect(sid, "cr", " customer.userid = '" + userEmailID + "'", -1, attrs));
wsUSD.logout(sid);
Add a web reference to the web services wsdl in Visual Studio (under Solutions Explorer, right click on References and click Add Web Reference).
If you are moving across environments I would recommend a .xml config file to specify the endpoint url to the WSDL.
Here is what it might look like in C# based on my use of it:
using webreference1;
public class WSExample
{
USD_WebService ws = new USD_WebService();
//set url when creating web reference to avoid this step
ws.Url = "http://yoursite.com/webservice?wsdl";
}
Now the ws object will allow you to access all of the methods specified in the wsdl. You can use the createRequest() method to create a request.
CA provides a Technical Reference guide, which includes web service methods. Consult their support site. If this is something you use frequently, I would recommend creating wrappers to abstract away the use of blank arrays.
Feel free to contact me if you need any additional support
A few months ago I wrote some PowerShell functions to look at CA Service Catalog and tell me basic things, like requests that were pending my actions, update request form details, etc. To do that I saved the wsdl xml file, cooked a .cs and then a compiled a .dll file.
Normally, I'd use this PowerShell function to compile a dll:
function get-freshDll {
param($url,$outDir)
$wsdl = #(Resolve-Path "C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\x64\wsdl.exe")[0].Path
$cscPath = #(Resolve-Path "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe")[0].Path
& $wsdl $url /out:$outDir"\WebService.cs"
& $cscPath /t:library /out:WebService.dll $outDir"\WebService.cs"
}
which works for the other CA stuff, just not Service Catalog (which is what I care about). For Service Catalog you have to save the wsdl file and chop out the DataHandler node (maybe someone else knows how to work with it, I gave up). After that the basic flow to create the dll is the same (just point wsdl.exe at the saved/edited wsdl file instead of the url) and then compile the dll with csc.exe. Add a reference for this dll to your C#/VB project. Working in Service Desk the PowerShell function above should work just like it is, just feed it the wsdl url and the dir where you want the dll to end up (you may also need to change the directories for your specific versions of netfx and .net).
Once the dll is mounted in your project you can use the Object Browser to see the methods that it contains. I'm still working it out myself (hence I found this post, and if you think Service Desk is hard to find examples for, try Service Catalog!). I don't have a good reference for Service Desk, sorry, but this is the .cs code (almost literally) that got the getRequests and getPendingActions methods to populate a GridView from the Service Catalog API. The aspx:
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
<asp:GridView ID="GridView2" runat="server">
</asp:GridView>
</asp:Content>
Keep in mind this is from a web app so there's a line missing from above:
<%# Page Title="" Language="C#" MasterPageFile="~/Site.Master" .... blahblah #%>
The .cs code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Http;
using System.Net.Http.Formatting;
namespace MyNamespace
{
public partial class MyRequestStuff : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
RequestServiceImplService reqService = new RequestServiceImplService();
reqService.CookieContainer = new System.Net.CookieContainer();
string user = "userid", password = "password", unit = "Unit";
reqService.Url = "http://servicecatalog/usm/services/RequestService?wsdl";
string session = reqService.logIn(user, password, unit);
var myRequests = reqService.getRequests(session);
var myPending = reqService.getPendingActions(session, user);
reqService.logOut(session);
GridView1.DataSource = myPending;
GridView1.DataBind();
GridView2.DataSource = myRequests;
GridView2.DataBind();
}
}
}
Like baultista and za7ef mention in their code, you'll need to create an USD_WebService object (instead of RequestServiceImplService) and use the methods available there (like getStatuses()), the functionality will be pretty similar (they are in PowerShell). I know it's not quite on point (e.g. SC instead of SD) but I hope that you or someone else finds this example useful.
For my application, I have a page that redirects to another page (within the same application) via Server.Transfer. I need to do this because the original page has an object that I need to access by using the Page.PreviousPage property.
Once my "destination" page has been fully loaded, a local deep clone that I made of the source page's object is suddenly released from memory once I perform a postback? Is this by design--something to do with the Server.Transfer?
An example...
Page1.aspx:
Public Structure myCustomObject
Implements ICloneable
Dim someField as String = "default value" ' Default value
Public Function Clone() As Object Implements System.ICloneable.Clone
Dim temp as new myCustomObject
temp.someField = Me.someField
Return temp
End Function
End Structure
Dim obj As myCustomObject
Public ReadOnly Property objProp as myCustomObject
Get
Return obj
End Get
End Property
objProp.someField = "changed value from source page"
Server.Transfer("page2.aspx", True)
Page2.aspx:
(onLoad)
Dim newObj As myCustomObject
newObj = Page.PreviousPage.objProp.Clone()
Debug.Write(newObj.someField) ' Output: "changed value from source page"
At this point, EVERYTHING works as it should. Stuff got cloned over correctly and all is well.
(Let's say this is on a button click event)
Debug.Write(newObj.someField) ' Output: "default value"<- This is NOT "changed value from source page" for some reason when it was working literally a few lines ago!
It's around here that I get the problem. My guess is that the Server.Transfer stops any association with the source page after the new page loads.
Is there a better way for cross-page object passing?
Just pass a variable in the HttpContext, you will have to handle your casting, not sure what Page.PreviousPage is:
Current Page:
HttpContext CurrContext = HttpContext.Current;
CurrContext.Items.Add("PreviousPage", Page.PreviousPage);
Transfered to page:
HttpContext CurrContext = HttpContext.Current;
var previousPage = CurrContext.Items["PreviousPage"];
Sorry for the C#, there was no code and the question wasn't marked with VB.NET when I answered. Someone feel free to convert.
If anyone is still looking for the solution to this issue, it's more than likely the settings.AutoRedirectMode = RedirectMode.Permanent; setting in your RouteConfig.cs. Change it to settings.AutoRedirectMode = RedirectMode.Off;
public static void RegisterRoutes(RouteCollection routes)
{
var settings = new FriendlyUrlSettings();
// settings.AutoRedirectMode = RedirectMode.Permanent;
settings.AutoRedirectMode = RedirectMode.Off;
routes.EnableFriendlyUrls(settings);
}
I've got a HTTPHandler which returns a lump of HTML. What's the best way to inject this into a control on the server?
I've got it mostly working by using an asp:literal and using WebClient.downloadString() to grab the text from the handler
<asp:Literal runat="server" ID="Text_Page1" Visible="false"></asp:Literal>
<asp:Literal runat="server" ID="Text_Page2" Visible="false"></asp:Literal>
and then in the server-side methods:
Text_Page1.Text = new WebClient().DownloadString("http://localhost:666/" +sPage1URL);
Text_Page2.Text = new WebClient().DownloadString("http://localhost:666/" +sPage2URL);
The hardcoded web-address is just there for testing at the moment. Previously I tried just using "~/" +URL to try and build it up but the WebClient library threw an exception saying that the URL was too long (which is not true I don't think)
Any ideas on the best way to do this from the server-side?
Edit : When I say "Best" I mean most efficient and adhering to "best practices". My method doesn't work so well when it's put onto an authenticated IIS. I'm having trouble authenticating. I thought that doing
WebClient oClient = new WebClient();
oClient.Credentials = CredentialCache.DefaultCredentials;
oClient.UseDefaultCredentials = true;
String sData = oClient.DownloadString(sURL);
would work but i get a 401 error. Does anybody have any alternatives?
Cheers
Gordon
Without asking any questions about the reasoning behind fetching html via a webrequest from the same application serving the contents of the include, i would wrap the functionality in a WebUserControl. Something along the lines of:
using System;
using System.Net;
using System.Web.UI;
public partial class HtmlFetcher : UserControl
{
//configure this somewhere else in the real world, web.config maybe
private const string ServiceUrl = "http://localhost:666/";
public string HtmlPath { get; set; }
protected override void Render(HtmlTextWriter output)
{
string outputText = String.Empty;
try
{
outputText = new WebClient().DownloadString(string.Format("{0}{1}", ServiceUrl, HtmlPath));
} catch (Exception e)
{
//Handle that error;
}
output.Write(outputText);
}
}
This is how you would add it to your page:
<%# Register src="HtmlFetcher.ascx" tagname="HtmlFetcher" tagprefix="uc1" %>
<uc1:HtmlFetcher ID="HtmlFetcher1" HtmlPath="some-test-file.html" runat="server" />
you will get the data in the string lcHtml then use it as you want
// *** Establish the request
string lcUrl = "http://yourURL";
HttpWebRequest loHttp =
(HttpWebRequest) WebRequest.Create(lcUrl);
// *** Set properties
loHttp.Timeout = 10000; // 10 secs
loHttp.UserAgent = "Code Sample Web Client";
// *** Retrieve request info headers
HttpWebResponse loWebResponse = (HttpWebResponse) loHttp.GetResponse();
Encoding enc = Encoding.GetEncoding(1252); // Windows default Code Page
StreamReader loResponseStream =
new StreamReader(loWebResponse.GetResponseStream(),enc);
string lcHtml = loResponseStream.ReadToEnd();
loWebResponse.Close();
loResponseStream.Close();
You can use server side code blocks into your aspx with <% %>.
Try this:
<% new WebClient().DownloadString("http://localhost:666/" +sPage1URL) %>