|
Thanks alot will try it out
|
|
|
|
|
Hello
I have to user controls on the same window and I would like to call a method in user control B from user control A. The method in user control B is public.
At the moment I have no clue how I would go about doing this. Any help would be greatly apreciated.
|
|
|
|
|
I don't have Visual Studio in the laptop I am currently using. But this should work. Main thing is that you will get the idea as to how to do this.
Assume you the following 2 user controls in your .aspx
ParentPage.aspx
<%@ Register src="Control1.ascx" TagPrefix="uc" TagName="Control1" %>
<%@ Register src="Control2.ascx" TagPrefix="uc" TagName="Control2" %>
<uc:Control1 runat="server" ID="ctrl1" />
<uc:Control2 runat="Server" ID="ctrl2" />
ParentPage.aspx.cs
public partial class ParentPage : Page
{
public Control1 getControl1()
{
return ctrl1;
}
public Control2 getControl2()
{
return ctrl2;
}
}
In the user control you could do the following:
Control1.ascx.cs
public partial class Control1 : UserControl
{
public void Page_Load(...)
{
ParentPage myPage = (ParentPage)this.Parent;
Control2 ctrl2 = myPage.getControl2();
}
}
Hope you understand this. Else post your questions here, when I get to a computer w/ VS, should be a lot easier!
[Edit] While answering this I assumed that you are referring to a web page. This wouldn't be the same for a win forms app (just now i noticed you have said "window" and not "page" and that this is the C# forum and not the ASP.Net forum). But the idea would be similar - instead of page, you would be getting the Form's instance (the parent) which exposes 2 methods to return the user control id's, thereby enabling you to call that control's methods.
Cheers,
Karthik
modified on Thursday, October 21, 2010 11:01 PM
|
|
|
|
|
There are 2 things user control A needs to do:
- Get a reference to user control B (assume it's named
ctrlB and is of type CtrlB ).
- Call the appropriate method (assume it's named
DoSomething() ).
Control ctrlB = this.Parent.Controls.FirstOrDefault (p => p.Name.Equals ("ctrlB"));
Debug.Assert (ctrlB != null);
((CtrlB) ctrlB).DoSomething();
/ravi
|
|
|
|
|
Not sure about why you want to do someting like this, becouse this way your user control A will depend too much on your user control B and vice versa. I guess you should better place an event into your user control A, and make your user control B subscribe to this event.
|
|
|
|
|
I have found a way to do it now but the reason for doing it is because UC A is a custom treeview where an item can be selected and once selected it populates UC B which is a form containing text fields.
|
|
|
|
|
Ok, then I think the best way to go in this case would be subscribing the form to the AfterSelect event (I guess you have inherited the TreeView control) and call the method on your B control whithin this handler.
I am telling you this becouse this way you will be able to reuse your custom treeView in other future projects where, maybe, you might need to populate a different set of controls with some different information.
|
|
|
|
|
Hello guys,
I have an app made that worked with the old Google Keywords Tool External. It worked perfectly until a few days ago when they dropped the new interface. Now I can't seem to crack this myself, and I need some help.
Using opera dragonfly (helps debug http requests) I managed to see how everything looks "in the background" but I don't understand a thing now. With the old site,everything was crystal clear, but now it's not.
The new website is located here:https://adwords.google.com/o/Targeting/Explorer?__u=1000000000&__c=1000000000&ideaRequestType=KEYWORD_IDEAS#search.none
When you want to get keyword results (enter a keyword and press enter), google makes a POST request here:
https://adwords.google.com/o/Targeting/g?__u=1000000000&__c=1000000000
The request headers are:
Host adwords.google.com
User-Agent Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.11) Gecko/20101012 Firefox/3.6.11
Accept text/html,application/xhtml+xml,application/xml;q=0.9,*
Now I don't understand what X-GWT-Permutation is (anx all the other x-gwt). I know it's google web toolkit ... but how the hell can I make a "call"to this website from c# .net (using httprequest) ?
The post content sent is:
6|1|69|https:
How should I send this? Like "uploading" a file? It's not a normal http post, because it has no variables, it's a simple text that it's sent.
So to make things short, I want to "download" the google keyword tool external page, and get the results in C# .net so I can process them.
Can anybody help?
Thanks in advance,
Vlad
|
|
|
|
|
Hi,
I'm not familiar with the Google interfaces, however I managed to do some other POSTs a few weeks ago, and basically this page[^] was all I needed.
sodevrom wrote: It's not a normal http post, because it has no variables, it's a simple text that it's sent.
It doesn't matter what the post data is, just write it to the stream, then proceed with accepting the result using HttpWebRequest.GetResponse() and HttpWebResponse.GetResponseStream() .
So if it worked for you earlier, there should not be a major problem (unless you want to understand what it is you are posting).
|
|
|
|
|
Hello,
I know how to use the httpwebrequest/response I am not really a "noob" in programming.
Now I decided to take a totally different approach, and get the text that I need by using a WebBrowser control. This is the best way to go I think, because it takes care of all the problems.
I have only one issue. For example to complete a field I use this:
HtmlElement username = this.wb.Document.All["username"];
username.SetAttribute("value", "aaaaa");
But how do I get the entire text of the webbrowser? It seems that if I use webBrowser1.DocumentText , it does not retrieve all the HTML code (it does not return everything that is visible). I think the problem is with dynamic code (javascript)
How do I get everything?
Thanks,
Vlad
|
|
|
|
|
Vlad,
you should receive the KeywordsTool data (keywords, CPC etc) using such code:
CComQIPtr<IHTMLElement, &IID_IHTMLElement> pBody;
CComQIPtr<IHTMLDocument2, &IID_IHTMLDocument2> pDoc2;
CComPtr<IDispatch> pDisp = NULL;
CHECKPTR(pDisp = objExplorer.get_Document());
CHECKPTR(pDoc2 = pDisp);
HRESULT hr;
hr = pDoc2->get_body( &pBody);
BSTR BSTR_Page = NULL;
if (pBody){
hr = pBody->get_innerHTML( &BSTR_Page );
}
/
if (BSTR_Page){
sPage= (LPWSTR) BSTR_Page;
SysFreeString(BSTR_Page);
}
|
|
|
|
|
to set certain HTML elements in the page, you could iterate through the page element collection and check for the class name / id etc you need.
Note after DISPID_DOCUMENTCOMPLETE the KeywordTool's JavaScript starts to amend the document. So you would need to poll the page content every X milliseconds to check if the elements you require have been created.
VariantInit(&index);
V_VT(&index) = VT_I2;
V_I2(&index) = 0;
CComPtr<IHTMLElementCollection> pEltColl = NULL;
CComPtr<IDispatch> pEltDisp = NULL;
CComQIPtr<IHTMLDocument2, &IID_IHTMLDocument2> pDoc2;
CComPtr<IDispatch> pDisp = NULL;
CHECKPTR(pDisp = objExplorer.get_Document());
CHECKPTR(pDoc2 = pDisp);
HRESULT hResult,hr;
hResult = pDoc2->get_all(&pEltColl);
if (SUCCEEDED(hResult) && pEltColl)
{
// Search by value (manual search with a loop on all HTML Elements in document - could be long!)
long intElements = 0;
pEltColl->get_length(&intElements);
for (int intElement = 0; intElement < intElements; intElement++)
{
CComPtr<IDispatch> pCurrentDispatch = NULL;
VARIANT vElementIndex;
VariantInit(&vElementIndex);
V_VT(&vElementIndex) = VT_I4;
V_I4(&vElementIndex) = intElement;
hResult = pEltColl->item(vElementIndex, index, &pCurrentDispatch);
if (SUCCEEDED(hResult)) {
CComQIPtr<IHTMLElement, &IID_IHTMLElement> pCur_Element = pCurrentDispatch;
|
|
|
|
|
Last time I used an event handler was to detect when a given track that is being played by the media element had ended, which was not difficult simply because the media element has an event called media ended. (http://msdn.microsoft.com/en-us/library/system.windows.controls.mediaelement.mediaended.aspx[^])
However what if the class your working with don't have events, I am working with the socket class and would like to set an event handler to listen for any incoming connection. So for as you can see from the code below I am using a button click event to trigger the application to begin listneing, which isn't that I want. I would like the application to start listening for in coming connections from the get go. How to I do this:
private void BtnListen_Click(object sender, RoutedEventArgs e)
{
Socket listener = new Socket(AddressFamily.InterNetwork,
SocketType.Stream,
ProtocolType.Tcp);
listener.Bind(new IPEndPoint(IPAddress.Any, 2112));
listener.Listen(10);
while (true)
{
Socket socket = listener.Accept();
string receivedValue = string.Empty;
byte[] receivedBytes = new byte[1024];
int numBytes = socket.Receive(receivedBytes);
receivedValue = Encoding.ASCII.GetString(receivedBytes,
0, numBytes);
if (receivedValue.Length < -1)
{
break;
}
else
{
MessageBox.Show(receivedValue);
break;
}
listener.Shutdown(SocketShutdown.Both);
listener.Close();
}
listener.Close();
Another problem I am having is that once the listen button is clicked, the application freezes until it receives something.
}
|
|
|
|
|
Look at Socket.BeginReceive (MSDN)[^] It should solve both problems if you read the documentation.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
Hi,
1.
I didn't look at your code as it isn't formatted properly. Please use PRE tags for code snippets.
2.
Communication stuff should not be handled synchronously on the main thread; either use asynchronous "non-blocking" calls, or, better yet, use a separate thread. That will stop your GUI freezing problem.
3.
When you want your button-click code to execute right away, then don't put it in a button_click handler! Why not put it in your Form's constructor, its Load event handler, or, best, its Shown handler.
|
|
|
|
|
Have a look at this article hosted here in CP.
The while(true) within the main application thread is what freezes your application.
Bye
|
|
|
|
|
I think you will find it's not:
int numBytes = socket.Receive(receivedBytes); Receive is a blocking call, so it will not return until the receive is complete. He has a break on each of the if and else conditions which would terminate his loop, if it ever got that far...
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
You are absolutely right. I was just trying to avoid the next question once he finds out how to receive asynchronously: Why is my application still freezing?
Ok, just kidding. The truth is that I did not pay attention to the code.
|
|
|
|
|
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
hey
- Windows mobile 6.5
- net 2.0
- Form with the x or the ok at the rigth upper corner
what i want to do
- start the program and the button = OK
- if you use a menu the button change to X
all that works but now it comme
if that button = X and i hit it then the program minimize
i want to change this to close the menu
i tryed already wndproc but this don't work in mobile or i don't find it
if any one has suggestions or solutions , links thanks therefore
thanks
|
|
|
|
|
Hi,
I have following string.
"sdate=2,edate=3,,frq=price(sdate=0,,),curn=usd"
I would like to split the above string as below.
string[0]="sdate=2"
string[1]="edate=3"
string[2]="frq=price(sdate=0,,)"
string[3]="curn=usd"
I tried to split based on ',', but I didn't get as above?
Please help.
|
|
|
|
|
SRKSHOME wrote: edate=3,,frq
The thing is you have two ,'s here.
Based on this string[2] will be "".
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
My latest tip/trick
Visit the Hindi forum here.
modified on Thursday, October 21, 2010 2:29 PM
|
|
|
|
|
no..string[1] would be edate=3 and string[2] would be ""
|
|
|
|
|
Missed that - thanks.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
My latest tip/trick
Visit the Hindi forum here.
|
|
|
|
|
Look into Regular Expressions.
Also see what I did here[^].
|
|
|
|