Attempting to render a PayPal smartbutton in asp View tag using .net 3.5. Here's a sample of the code:
The client_id and PayPal button are included in the actual code.
Any help is appreciated
Was able to resolve by calling JS code from code-behind, e.g.:
ScriptManager.RegisterStartupScript(Me.Page, Me.GetType(), "ShowButton", "loadButton();", True)
Related
I've searched the answer all over and can't seem to find it. I'm using Hubspot and hate the way their lead forms look, so I'm taking advantage of their "track non-Hubspot forms" feature. The problem on WordPress is that they track the login form for admin, which sends false leads to my client's Hubspot.
Because the tracking code is something I simply place in the header for all pages, I'm trying to find the right way to prevent tracking only on pages where the URL contains 'login' or 'admin'.
I tried using JS to check if the URL contains the above terms, but I am having trouble figuring out how to only add a script if the boolean is true. Code below.
<script type="text/javascript" async defer>
//Statement is true if URL isn't a login or admin page
if(!window.location.contains('login') && !window.location.contains('admin')) {
<!-- Start of HubSpot Embed Code -->
<script type="text/javascript" id="hs-script-loader" async defer src="//js.hs-scripts.com/5562596.js"></script>
<!-- End of HubSpot Embed Code -->
}
</script>
I realize now you can't have a script within a script. What I want is for the Hubspot script to only execute if the URL doesn't contain 'login' or 'admin' so we can avoid getting false lead form submissions in Hubspot. Any help would be greatly appreciated!
You can config this in your account of hubspot: option chatflow, section.
add exclusions
This option works for me.
I have an ASPx/C# page that on clicking Save it will post back to the server. If the content within the controls already exists in the data stores which are checked it is supposed to pop-up an alert. The previous programmer used:
<asp:Literal ID="litError" runat="server" />
with the code behind ultimately sending:
litError.Text = "<script type='javascript'>alert('An error occured while processing this request. If the error persists, please contact the help desk.');</script>";
This JS alert is not popping up in spite of the debug reporting everything correctly processing through. I have scoured the internet, including here, for several days trying to find a resolution. I have tried many variations to get this to fire.
I'm suspecting that the script cannot fire on the AJAX because it is just not there during the Load stage of the life cycle, but would like some verification.
The script is in the btnSave_OnClick method. Unfortunately, due to the nature of the web application I cannot show more of the code, but the script should fire on exception of an item existing in either the app DB or if the user exists in our AD system already.
I was able to resolve my issue by completely removing the use of the ASP Literal control. I believe my first attempts at using this didn't have a properly formatted string, but it is now correctly functioning with the below code implemented in the code behind:
StringBuilder sbError = new StringBuilder();
sbError.Append("<script language='javascript' type='text/javascript'>alert('" + strError + "');</script>");
ScriptManager.RegisterStartupScript(this, this.GetType(), "sbError", sbError.ToString(), false);
Thanks to Zaigham and James for trying to help. I believe the reason the Literal control method did not work was because there was a ScriptManager control on the page(s) that were attempting to use that method.
I am not exactly sure why the script in literal is not working, but you can try this instead.
Your script text
string script = "<script>alert('Your alert message goes here');</script>";
Then use the method RegisterClientScriptBlock (in the same event where you previously set the error text) to inject the script to the page during the postback.
Page.ClientScript.RegisterClientScriptBlock(typeof(YOUR_PAGE_TYPE), "alert", script);
When the page is loaded back, you should see the alert popped up.
what I understand is; you want to run client script from code behind in the button click event (based on a condition). The best way to achieve this is to use ScriptManger class. Example:
Protected void btnSave_OnClick()
{
ScriptManager.RegisterStartupScript(btnSave, btnSave.GetType(), "myscript",
"alert('Your alert message goes here');", true);
}
I inherited some code that uses ASP.NET AJAX pageLoad client side event.
The code runs fine and the method is called when the page is opened in the server in an URL such as http://localhost/IISApp/page.aspx, but when I open it in the server with URL http://ServerName/IISApp/page.aspx, the pageLoad is not called.
Any idea on what may be causing the behavior? This happens in Firefox and IE.
Update:
The pageLoad is in a separate file, and is declared as
function pageLoad(sender, args)
{
....
}
This file is included in the master page as:
<asp:ScriptReference Path="~/js/functions.js" />
It's running is IIS7, there are no special configurations in IIS for when a user hits the site with server name or localhost. If I run it from VS 2010 (Cassini web server), the method is also not being called.
Thx in advance
You need to add a script manager to your aspx page,
or you can add the following script to the page head
document.body.onload=pageLoad;
regards
I am trying to add a script reference to the script manager in the event of a Microsoft AJAX Partial Postback, ie a user clicks on a link in an Update Panel.
ScriptManager.RegisterClientScriptInclude(Page, Page.GetType(), "UniqueName",
Page.ResolveUrl(scriptPath));
Doesn't work and either does
ScriptReference script = new ScriptReference(scriptPath);
MyScriptManager.Scripts.Add(script);
From what I have read on the net, RegisterClientScriptInclude should work even in a partial postback.
http://www.codeproject.com/KB/ajax/addingCssJsAjaxPartialPos.aspx
Can anyone give any ideas why these don't work, or another way to do it?
EDIT: Additional information.
I am working with a very large legacy code base that has the forms and script manager in each page rather than in the master page. I would like to place the code into a class and use the following call to add the javascript effect.
ClientSideScripts.BackgroundColourFade(Page, ScriptManager, Control);
The reasons I want to include the script in the method call is
Consumes of the method don't have to remember to include the script
Changing the script used only requires a change in one place
Only include the javascript when needed to keep the load time of the page down
Have a look at this SO-Question because it answers your question:
ScriptManager.RegisterClientScriptInclude does not work in UpdatePanel
function dynamic() {
alert('dynamic');
$('#divDyn').text('Dynamic!');
}
// notify that the script has been loaded <-- new!
if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
i am writing an Adobe Air application using flex builder.the application loads a URL using HTML control and URLLoader.
the problem that the page has an instant redirection JavaScript that redirects the page to another one. I would like to disable that redirection.
I think this can be achieved either by disabling JavaScript on page load or telling the HTML control that do not follow the direction. i don't know how to do that?
thank you so much.
hey, i found a solution to load html source for a remote html document without loading it in htmlloader.so the javascript will not redirect me.
here is the code (from htmlscout sample application of adobe dev).
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE,
function(e:Event):void
{
trytogetsource.text = loader.data;
});
loader.load(new URLRequest("http://www.google.com"));