|
Using C# how do I access another page within the project and call a function that is
public to it? Do I simply declare a variable as that page name and invoke the function
on the variable? Does that work even if the page has already been loaded?
I guess I'm wondering if I have to use a FindPage() or something in order to get the
instance of the page that has already been displayed...
I suppose I could just check in the Page_Load for a QueryString and if it's there have
the page call the function on it's own but that seems to be harder than it should be...
|
|
|
|
|
it is simple class call. Forget that it is a page and access the function as in a seperate class.
Page 1
namespace TEST
{
public class PAGE1 : System.Web.UI.Page
{
--------------------
private void Page_Load(object sender, System.EventArgs e)
{
PAGE2 obj = new PAGE2();
Response.Write(obj.test());
--------------------------
-------------------
-----------------
Page 2
namespace TEST
{
public class PAGE2 : System.Web.UI.Page
{
------------------------
---------------------------
public string test ()
{
return "SREE";
}
------------------------
---------------------
Sreekumar PP
|
|
|
|
|
Well that would work fine but the Page name also happens to be a namespace name (not my code, cannot change it) how do I indicate I want an instance of the page not the namespace? Right now the compiler is erroring because it's treating it as the name space.
|
|
|
|
|
Hi Rex,
When a function in a web page can be reused somewhere else, then IMO that's a good candidate for refactoring, you may put this code in a common class so that you can easily reuse it without having to initialize a new instance of the web page.
|
|
|
|
|
asp.net 1.1. We have a user control named mhcuc in our project which has got two public properties and one method(which is actually used to access the property and attach javascript click event to child control) and it contains one linkbutton child control. We have two instances of user control in the same page. We have assigned property values for one instance and called method to attach onclick attribute and assigned this instance to another instance. But the first instance click works and not the second instance. Do you we need to assign in a different manner? The properties are seen in both the controls while debugging. Help needed
|
|
|
|
|
IMO, you may consider using the delegate to communicate between the user controls instead of assigning one instance to another.
|
|
|
|
|
Hello,
I am converting a DateTime variable to a string in RFC1123 format (RSS) using the following code:
Dim a As DateTime
a = DateTime.Now
Dim b As String = a.ToString("R")
It works.
Now I want to make the same but with a Date/Time field from an Access Database.
The problem is that is when I get the field it comes as string.
I tried to use String.Format(MyField, "R") but I still get the string date as "9/16/2006".
How can I solve this?
Thanks,
Miguel
|
|
|
|
|
If you really have a Date/Time field in the database, you don't get the value as a string, but as a DateTime value.
You have swapped the parameters in the call to the Format method, that might be the reason for your problem. The format string is the first parameter, and if you put your DateTime value there, it will be converted to a string and used as the format, and as it doesn't contain any formatting the result will just be that string.
---
b { font-weight: normal; }
|
|
|
|
|
Hi,
I really have a Date/Time in my database.
About the swapping I believe you are mistaken.
I tried String.Format("R", MyField) and I got R as a result of it.
Was this what you were talking about?
Thanks,
Miguel
|
|
|
|
|
shapper wrote: I tried String.Format("R", MyField) and I got R as a result of it.
That is because the "R" string doesn't contain any formatting either.
Try "{0:R}" instead.
---
b { font-weight: normal; }
|
|
|
|
|
Hello,
I have a string which holds a text.
Is it possible to create a substring which uses the first N words of
that string?
Thanks,
Miguel
|
|
|
|
|
private string GetWords(string Sentence, int NumberOfWords)<br />
{<br />
string[] Words = Sentence.Split(' ');<br />
int Length = Sentence.IndexOf(Words[NumberOfWords-1]) + Words[NumberOfWords].Length-1;<br />
return Sentence.Substring(0, Length);<br />
}
only two letters away from being an asset
|
|
|
|
|
Interresting solution...
Try:
GetWords("This may come as a surprise, but the result is not as expected...", 10)
The result is "This" .
---
b { font-weight: normal; }
|
|
|
|
|
I got this solution:
string nWordStr = String.Join (" ", originalString.Split (' '), 0, N);
Thanks,
Miguel
|
|
|
|
|
Yes that would work. It uses a bit more resources than finding out how many characters you need and simply getting them, but at least the code is simple.
It's a bit less inefficient if you limit the number of items in the split rather than in the join:
string nWordStr = String.Join (" ", originalString.Split (' ', N));
This way the array that is created doesn't contain all the words in the text, only the words needed.
---
b { font-weight: normal; }
|
|
|
|
|
Damn, not enough testing. I just thought it up quickly.
This worked
GetWords("The Lazy Brown Fox", 2);
but i guess it should be
GetWords("The Lazy Coder didn't test well enough", 2);
only two letters away from being an asset
|
|
|
|
|
Hi all,
I've noticed that almost all of you who do some kind of dynamic imaging in web applications use the System.Drawing namespace and it's descendants. Is it only me, or are the rest of you also closing your eyes real hard (while remembering to be extra careful about when and what to Dispise()... um... Dispose() in your app) when you come across the following text in the reference?
Caution: Classes within the System.Drawing namespace are not supported for use within a Windows or ASP.NET service. Attempting to use these classes from within one of these application types may produce unexpected problems, such as diminished service performance and run-time exceptions.
Are they serious, or is this just to avoid having to support people who don't realize that they run in a server environment and don't program defensively enough? Does anyone have any real world experience of high-volume sites getting away with using System.Drawing? I have a couple of low-volume sites going, and as I normally only invoke System.Drawing each time I need a size or format I've never seen before (all old renderings from original images are cached to disk), it really never gets stressed, so it sort of doesn't count...
Peter, after midnight
|
|
|
|
|
Hello there,
I've been working on a small Web Service for my school to allow me to create users in an Active Directory. What I've been doing as my - probably faulty - developing process is to create a Windows Application and when the code is working correctly, I copy it to my Web Service code, fine tune it, and it's ready to go.
But the odd thing here is that when my code creates a user in the domain through the WebService, it creates the user with its account disabled even when I have put code to explicitly enable the account. Yet, if I run the same exact code from the Windows App, it creates the user account enabled.
I don't know if it's a question that has been answered before, or if for some security reason that's the way Web Services create user account by default.
Oh! By the by, the Web Service is running on a machine with Windows 2000 Professional, with the .Net 2.0 framework installed an configured; whereas the app in which I tried the code runs on a Win XP machine. Both machines are members of my school's domain. Maybe that has to do with it.
private void addUser(string user, string name, string lastName, string password)<br />
{<br />
try<br />
{<br />
DirectoryEntry adUserFolder = new DirectoryEntry("LDAP://10.32.62.9/CN=Users,DC=some,DC=domain,DC=here", "someuse", "somepassword");<br />
if (adUserFolder.SchemaEntry.Name == "container")<br />
{<br />
DirectoryEntry newUser = adUserFolder.Children.Add("CN=" + user, "User");<br />
<br />
DirectorySearcher search = new DirectorySearcher(adUserFolder);<br />
search.SearchScope = SearchScope.Subtree;<br />
search.Filter = "(&(ObjectClass=user)(cn=" + user + "))";<br />
SearchResultCollection res = search.FindAll();<br />
if (res.Count > 0)<br />
{<br />
return;<br />
}<br />
<br />
newUser.Properties["sAMAccountName"].Value = useer;<br />
newUser.Properties["givenName"].Value = name;<br />
newUser.Properties["SN"].Value = lastName;<br />
newUser.Properties["displayName"].Value = name + " " + lastName;<br />
<br />
newUser.CommitChanges();<br />
<br />
newUser.Invoke("setpassword", password); newUser.CommitChanges();<br />
<br />
newUser.Properties["userAccountControl"].Value = 0x200;<br />
<br />
newUser.CommitChanges();<br />
}<br />
}<br />
catch (DirectoryServicesCOMException e)<br />
{ Console.WriteLine(e.Message); }<br />
catch (Exception e)<br />
{ Console.WriteLine(e.Message); }<br />
}<br />
<br />
Thanks in advance!
|
|
|
|
|
Hello,
I did some testing and realized that for some reason I still haven't figured out when the code is run from a Web Service the password is not even set. It is as if these lines did not execute:
newUser.Invoke("setpassword", password);<br />
newUser.CommitChanges();<br />
newUser.Properties["userAccountControl"].Value = 0x200;<br />
newUser.CommitChanges();
Like I said, this exact same code runs a-Ok from a Windows App, but not from a Web Service.
|
|
|
|
|
Okay, figured out my error. I was missing some impersonate settings on the Web App. Solved now
|
|
|
|
|
Hi guys,
I have used following code
Response.AppendHeader( "content-disposition", "attachment;filename=" + FilePath );
Response.WriteFile(FilePath);
Response.End();
to get the download dialog box for one file on my server. Can any body tell me how can i get the response (Whether user has clicked Open, Save or Cancel button)???
Thanks in Advance
|
|
|
|
|
I don't believe that you can. Thie "open/save/cancel" options are handled entirely within the browser and do not send any data to the browser. The job of the server is simly to send the stream to the client and be done with it. The browser is responsible for receiving the stream and then asking the user what to do with it, which requires no server interaction.
|
|
|
|
|
Thanks Jim,
Is there any way to do same functionality?
|
|
|
|
|
I am using an ASP.NET 2.0 TreeView and was wanting to create different child TreeNode types for the different items that I am loading into the treeview. The idea behind this is that all I should have to do is check the node type when a node gets clicked and I can then respond accordingly. The problem, however, is that the child treenode I created that inherits from TreeNode gets reported to be a normal TreeNode type rather than the inherited treenode type when I use the typeof operator even though I instantiate it as the child TreeNode type. Am I missing something?
class Child1TreeNode : TreeNode
{
}
class Child2TreeNode : TreeNode
{
}
And then in the Page Load:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Child1TreeNode node = new Child1TreeNode();
node.Text = "Hello World";
node.Value = "1";
Child2TreeNode node2 = new Child2TreeNode();
node2.Text = "Goodbye World";
node2.Value = "2";
TreeNode topNode = TreeView.FindNode("Top");
topNode.ChildNodes.Add( node );
}
}
And then in the event handler for node changed:
protected void TreeView_SelectedNodeChanged(object sender, EventArgs e)
{
TreeNode node = ((TreeView)sender).SelectedNode;
if (node.GetType() == typeof(Child1TreeNode) )
{
}
else if (node.GetType() == typeof(Child2TreeNode) )
{
}
}
Thanks.
-Matt
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|
|
Hi there,
What you are missing is that you also need to extend the TreeView control and override the CreateNode method. This method is basically used on postback to recreate the nodes tree, and by default it returns the TreeNode type and has no idea about your custom Child2TreeNode .
|
|
|
|