I am using google translate element: http://translate.google.com/translate_tools for my entire website. I place the code generated in the master file so it is available on every page. Now, I have a few page where I do not want to use google's translation but my own. I am able to prevent the google from not translating a certain control, but now I have two drop downs box showing on my page. How can I get rid of one? either catching the value of the language selected in the googles dropdown or by somehow passing my own dropdowns value to the google dropdown and trigger a change. I have not been able to do either of them. I would appreciate any help here.
Thanks,
Ratan
If you wan to hide or remove google translator from some of your website pages, follow the following steps.
i: Place your google translator code e.g in asp.net panel
<asp:Panel ID="pnl" runat="server">
google translator code
</asp:Panel>
ii: On load or pre render event of page where you want to hide google translator code use the following code.
MasterPage mstr = Page.Master;
Panel pnl = (Panel)mstr.FindControl("pnl");
pnl.Visible = false;
Hope this will help you.
Related
I am coding a web browser control application that will perform some specific operations in a website.
There are, however, a couple pages of tables in the website, where transition in between is implemented with a Java Script command. Here is what I get when I use inspect element over one of the transition buttons:
<a class="ctl00_cph1_mnuPager_1" href="javascript:__doPostBack('ctl00$cph1$mnuPager','b2')"> 2 </a>
Given that I have already have the page in my c# application as follows:
HTMLDOCUMENT BrowserContent = webBrowser1.Document;
Can you give me any tips about how to programmatically click on that page transition button(ie. call that script).
I tried:
BrowserContent.InvokeScript("javascript:__doPostBack('ctl00$cph1$mnuPager','b2')");
But it didn't help.
Thanks a lot guys!
Try this:
BrowserContent.InvokeScript("javascript:__doPostBack('ctl00$cph1$mnuPager','2')");
This will invoke the script inside the double quotes.
I retrieve some html codes from database and I want to display this values in a webform.
You can see my code below. It does not display labels and textboxes. However when I View the .aspx page source in the browser I can see retrieved labels and textboxes with Eval. Why I can not see labels and textboxes in the page?
database values:
code behind:
using (BurganEntities burganEntities = new BurganEntities())
{
List<DynamicField> dynamicFields=(from dynamicField in burganEntities.DynamicField select dynamicField).ToList();
cdcatalog.DataSource = dynamicFields;
cdcatalog.DataBind();
}
aspx:
The fast answer is because asp,net controls are compiled server side but you using them as text on the final render html page - so you have skip this compile, and the asp.net page did not know nothing about them.
The solution is to avoid asp.net controls and use regular html controls. You can still get their return on code behind, you may miss some easy to use functionality, but you can make your work with alternative way.
Other possible solution is to read the database and dynamically create the controls. For example you can add a flag on your database line that says, now create a text box, and on code behind you just create that text box dynamically.
Your code is simply outputting the <asp:TextBox /> to the browser; it isn't parsing it with the WebForms processor to convert it to an <input /> element.
In your database, you should probably be storing:
<input id="txtsdsd" name="txtsdsd" class="textbox" onkeypress="return NumberOnly()" />
and then using Request.Form() to retrieve the value.
I'm not sure if you've started to write your dynamic controls but as an addition to second reply, I would like to mention more sources about dynamic controls.
Although there is no concept of controls in ASP.NET MVC any longer, you can follow ASP.NET webform data access page.
As you want to compile your code at server side; on any postback you will loose dynamic content. So read this and all done.
Or as you mentioned you didn't get values of textboxes, please see the following method,
var textBox = FindControl("<id_of_textbox>") as TextBox;
if(textBox != null)
{
var textBoxValue = ((TextBox)textBox).Text;
}
</id_of_textbox>
see FindControl method at this page
I have created a small web application for display the selected employees data. In this application I coded a javascript. I have create a dropdownbox with username details along with them a checkbox is in front of every user. These username get from database. I want that manager dropdown the list and select the employee which he want to see the details. I did this with the help of javascript but the issue is that it successfully display the usernames in dropdown when it is saparate form from the master page but when i merge it with master page means make it content page of that master page it doesn't display the usernames in dropdown.
It display it blank. Where I m doing wrong. Any suggestions will be appreciated.
Thanks in advance.
As Pleun says the masterpage will change the HTML control ids rendered to the browser. There are a couple of ways round this If you are using asp.net 4 you can specify the client ids as follows:
<asp:Label Text="text" runat="server" ID="SomeID" ClientIDMode="Static" />
That will maintain the ID rendered to the browser.
If you are user a previous version of asp.net then i tend to user JQuery to get the controls using something like:
$("[id$='SomeId']")
The $= means ends with.
You can also user server markup mixed in with your javascript code e.g.
var control = document.getElementById("<% =SomeId.ClientId %>");
asp.net will then render out whatever client side id it assigns to the control with server id SomeId
The master page changes the names of the controls:
Have a look here:
http://www.asp.net/master-pages/tutorials/control-id-naming-in-content-pages-cs
(Not your question - but the functionality can also be done out of the box with ASP.NET without coding javascript yourself)
You need to give the client id of the controls in the function.
When you were using master page den the id of ur controls changes.
For eg:
The clientID of Checkbox chktest will be chktest without master page.But with masterpage the clientID changes to something like 'ctl00_ContentPlaceHolder1_chktest'
So the javascript will not detect if you use chktest when using master page and your functions wont work as expected.So use clientId of controls.
I have a pretty simple web-form set up in .Net where I am leveraging jQuery for some of the functionality. I am using the DOMWindow portion for part of the presentation layer.
There is a login form in a div that is set to display:none. When a user clicks a button on the page, it displays the login form. However the .Net button for the login form will not fire it's event when display is set to none. If i take this out, it fires fine. I have also tried using the visibility attribute, but no luck.
the div code is:
<div id="Login" style="display:none;">
The launching code is:
click here to login.<br />
the jQuery code is:
function LaunchLoginWindow() {
$(document).append("#Login");
$.openDOMWindow({
loader: 1,
loaderImagePath: 'animationProcessing.gif',
loaderHeight: 7,
loaderWidth: 8,
windowSourceID: '#Login'
});
}
Any help or explanation that anyone can offer is appreciated.
I noticed i had some code in there defining a client-side function on the Login div. I removed this so as to eliminate it as a possible issue.
I can see in your code that you are appending the div #Login but not setting its style property back to normal like block so. Set it back to block and i am sure it will work
try adding somthing like:
$(document).append("#Login").show();
OK, after playing around with this using firebug, I found the issue: When the jQuery plug-in DOMWindow creates its display layer, it appends to the HTML node of the DOM, which places the control outside the asp.net form tag. Therefore the button and actions associated with it via the DOMWindow are not recognized by .Net. So i edited the DOMWindow source file to append to the DOM form node rather then the html node.
The drawback is that the source has now been customized and will have to be QA'd thoroughly, especially if any further changes are made. But I hope to manage this effectively via commenting in the file.
Hope this helps anyone else who hits this issue.
pbr
C# Visual Studio 2010
I am loading a complex html page into a webbrowser control. But, I don't have the ability to modify the webpage. I want to click a link on the page automatically from the windows form. But, the ID appears to be randomly generated each time the page is loaded (so I believe referencing the ID will not work).
This is the content of the a href link:
<a
id="u_lp_id_58547"
href="javascript:void(0)"
class="SGLeftPanelText" onclick="setStoreParams('cases;212', 212); window.leftpanel.onClick('cases_ss_733');return false; ">
My Assigned</a>
Is the anyway to click the link from C#?
Thanks!
UPDATE:
I feel like this is close but it is just not working:
HtmlElementCollection links = helpdeskWebBrowser.Document.Window.Frames["main_pending_events_frame"].Document.GetElementsByTagName("a");
MessageBox.Show(links.Count.ToString());
I have tried plugging in every single frame name and tried both "a" and "A" in the TagName field but just have not had any luck. I can just not find any links; the message box is always 0. What am I missing?
Something like this should work:
HtmlElement link = webBrowser.Document.GetElementByID("u_lp_id_58547")
link.InvokeMember("Click")
EDIT:
Since the IDs are generated randomly, another option may be to identify the links by their InnerText; along these lines.
HtmlElementCollection links = webBrowser.Document.GetElementsByTagName("A");
foreach (HtmlElement link in links)
{
if (link.InnerText.Equals("My Assigned"))
link.InvokeMember("Click");
}
UPDATE:
You can get the links within an IFrame using:
webBrowser.Document.Window.Frames["MyIFrame"].Document.GetElementsByTagName("A");
Perhaps you will have to isolate the link ID value using more of the surrounding HTML context as a "target" and then extract the new random ID.
In the past I have used the "HtmlAgilityPack" to easily parse "screen-scraped" HTML to isolate areas of interest within a page - this library seems to be easy to use and reliable.