I am trying to copy the text in clip board inside the repeater but it's not copying.
Below is what I have tried so far.
protected void rptCopy_ItemCommand(object source, System.Web.UI.WebControls.RepeaterCommandEventArgs e) {
if (e.CommandName == "Copy") {
System.Web.UI.WebControls.LinkButton btnCopy = (LinkButton) rptQuestResponseDtl.Items[0].FindControl("lnkCopy");
System.Web.UI.WebControls.Label txtMsg = (Label) rptQuestResponseDtl.Items[0].FindControl("lblComment");
txtMsg.Focus();
btnCopy.Attributes.Add("onclick", "function copyClipboard(){ CopiedTxt = document.selection.createRange();CopiedTxt.execCommand('Copy'); }");
}
}
should the onclick event be onclientclick like btnCopy.Attributes.Add("onclientclick",... ? Also you defined the function copyClipboard but never called it like copyClipboard()... My recommendation is define function in JS file, include it in your ASPX page and then use clientclick event to call the function
Related
I have to call a function in my JS by passing a vector as a parameter when the page loads.
I can do this using a p: commandButton, where here:
actionListener = "# {routeEnterBean.GetMap ()}"
I run the function in the Bean (getting values in the database) and then, here:
oncomplete = "initMap (xhr , status, args) "
Thus, the JS function is executed
Code Bean:
public void gerarMapa() {
RequestContext context = RequestContext.getCurrentInstance();
context.addCallbackParam("coord", new
org.primefaces.json.JSONArray(coordenadas));
}
Function JS
function initMap(xhr, status, args) {
var qtd_entregas = args.coord.length;
for (var i = 0; i < args.coord.length; i++) {
waypts.push({
location : args.coord[i].latitude + ', ' + args.coord[i].longitude,
stopover : true,
});
}
}
But I'm wanting to do this without having to click the button as soon as I load the page.
I know that it is possible to execute a function using this command:
RequestContext.getCurrentInstance().execute("testeJS();");
But I do not know how to pass a vector as a parameter
You can keep your existing code and do it using Primefaces p:remoteCommand by adding following line on your page
<p:remoteCommand autoRun="true" actionListener="#{routeEnterBean.gerarMapa()}" oncomplete="initMap(xhr, status, args);"/>
Attribute autoRun="true" will force p:remoteCommand to be executed on page load.
Team,
When I click on the first add template button then the download value disappear. .
window.onload = function() {
ddnameChange();
};
function ddnameChange() {
var e = document.getElementById("<%=ddltemplate.ClientID %>");
var ddnamevalue = e.options[e.selectedIndex].value;
if(ddnamevalue==2)
{
<%=btndownload.ClientID %>.value="Download RBH Template";
}
else if(ddnamevalue==3)
{
<%=btndownload.ClientID %>.value="Download VISTA Template";
}
else
{
<%=btndownload.ClientID %>.value="Download OD Template";
}
}
I am not able to get the second button value when i click on edit as well as all template button.I know it should be something reason like update panel that why the function is not calling I don't know how to solve it.
You have to add this in the method that handles the Async PostBack.
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "ddnameChange", "ddnameChange();", true);
When the Async PostBack occurs, everyting inside the UpdatePanel is rebuild and anything that has been altered by jQuery will be lost.
I'm developing a website for users where I add controls dynamically.
The problem is that after a confirmBox appears it doesn't matter what I click (Ok/Cancel) it still deletes my objects.
This is how I add them from codeBehind:
aPanel.RegisterAction("DeleteStuff", "Delete object",
true, btnDeleteClick, null);
where aPanel is ActionPanelDx
right after this comes:
if (actionPanel["DeleteStuff"] != null)
actionPanel["DeleteStuff"].ClientSideEvents.ItemClick =
"function(s,e){return confirm('Are you sure you want to delete?')}";
protected void btnDelete_Click(object sender, MenuItemEventArgs e)
{
//Im using self written classes for handlig SQL logic it looks like this:
MySQLCommand commad = new MySQLCommand("delete_object");//procedure
commad.MyParam.AddWithValue("#ob_id", ObjectID);
commad.myExecuteNonQuery();
}
Am I using the JS function in a wrong?
Now what your code does it to delete your object whenever a button (doesn't matter which) is clicked. What you need to do is something like that:
protected void btnDelete_Click(object sender, MenuItemEventArgs e)
{
if (e.item.name === "Yes")
{
MySQLCommand commad = new MySQLCommand("delete_object");//procedure
commad.MyParam.AddWithValue("#ob_id", ObjectID);
commad.myExecuteNonQuery();
}
}
instead of e.item.name it could be e.item.text or something like that, put a breakpoint or console.log to see what is inside of your e property if you not sure.
We are implementing an app where we have communication between Javascript and c#. Our UIWebView has a button to invoke some native functionality. On a UIWebView i have an handler on ShouldStartLoad.
webView.ShouldStartLoad = myHandler;
bool myHandler (UIWebView webView, NSUrlRequest request, UIWebViewNavigationType navType)
{
}
This gets called everytime page loads. Indeed, i would like to only call it from an event from WebView such as on a button click.
From Javascript i have
window.location.href = "myapp://action?par1=abc&par2=def";
How to call a particular function from custom url?
Calling JavaScript from c#
I am trying to call back JavaScript from c# but it is not calling TestShow() function
wkWebView.EvaluateJavaScript(string.Format("TestShow()"), (r, e) =>
{
Console.WriteLine("In EvaluateJavaScript");
if (e != null) Console.WriteLine(e);
});
JavaScript side i have a Alert but it is not showing that alert
function TestShow()
{
alert("Hello! I am an alert box!!");
}
You can either continue using UIWebView and parse the NSUrlRequest to see if it is the call you're looking for. Then return true/false accordingly.
A better option would be to use WKWebView and create a custom message handler. Something like this:
1) Implement IWKScriptMessageHandler (tested on the default UIView created by Xamarin UIViewController)
public class UniversalView : UIView, IWKScriptMessageHandler
{
public void DidReceiveScriptMessage(WKUserContentController userContentController, WKScriptMessage message)
{
var msg = message.Body.ToString();
System.Diagnostics.Debug.WriteLine(msg);
}
}
2) Create user controller with a handler for "myapp" (this = the IWKScriptMessageHandler)
var userController = new WKUserContentController();
userController.AddScriptMessageHandler(this, "myapp");
3) Create a config with the controller
var config = new WKWebViewConfiguration
{
UserContentController = userController
};
4) Create the WKWebView with the config
var webView = new WKWebView(new CGRect(10, 100, 500, 500), config);
5) Call "myapp" from your JS code
<html><head><meta charset = "utf-8"/></head><body>
<button onclick="callCsharp()">Click</button>"
<script type="text/javascript">
function callCsharp(){
window.webkit.messageHandlers.myapp.postMessage("action?par1=abc&par2=def");
}</script></body></html>";
EDIT: In regards to evaluating JS from C# you need to be sure the HTML page has finished loading or otherwise the call will result in an error. You can handle navigation events by implementing IWKNavigationDelegate
public class UniversalView : UIView, IWKScriptMessageHandler, IWKNavigationDelegate
{
[Export("webView:didFinishNavigation:")]
public void DidFinishNavigation(WKWebView webView, WKNavigation navigation)
{
webView.EvaluateJavaScript("callCsharp()", (result, error) =>
{
if (error != null) Console.WriteLine(error);
});
}
Assign it to the WKWebView you created:
var webView = new WKWebView(new CGRect(10, 100, 500, 500), config)
{
WeakNavigationDelegate = this
};
Objective:- From the server-side, I need to open a radwindow(defined in JavaScript of the aspx page) automatically on an IF condition.
Code used:-
In aspx page, I defined the radwindow as:-
<telerik:RadWindowManager Skin="WBDA" ID="AssetPreviewManager" Modal="true"
EnableEmbeddedSkins="false" runat="server" DestroyOnClose="true" Behavior="Close"
style="z-index:8000">
<Windows>
<telerik:RadWindow ID="DisclaimerAlertWindow" runat="server" Width="720px" Height="220px"
Modal="true" visibleStatusbar="false" VisibleTitlebar="false" keepInScreenBounds="true" title="Sourav">
</telerik:RadWindow>
</Windows>
</telerik:RadWindowManager>
In JavaScript, a function is defined for opening the radwindow:-
function openRadWindow()
{
var oWnd = radopen('DisclaimerAlert.aspx, 'DisclaimerAlertWindow');
oWnd.set_title('Access Denied !');
oWnd.Center();
return false;
}
So on the server side of the aspx page, In the Page Load event an IF condition is checked and then I'm calling 'openRadWindow()' function as:-
protected void Page_Load(object sender, EventArgs e)
{
if (fieldValue == "False")
{
string xyz = "<script type='text/javascript' lang='Javascript'>openRadWindow();</script>";
ClientScript.RegisterStartupScript(this.GetType(), "Window", xyz);
}
}
Problem:-
But on running this, these JavaScript errors are coming:-
Object doesn't support this property or method.
'undefined' is null or not an object
Please help how to achieve my objective. I am totally stuck.
Hi I want to share with you my solution to create RadWindow dialog in Javascript code only.
We need to implement 2 methods: one for initializing RadWindow dialog, and the last one for recieving the arguments returned after closing the RadWindow. You can do what you want in this second step (e.x postback,...)
Here is my code:
Initializing RadWindow dialog:
function openMyDialog(url, args) {
var manageWindow = GetRadWindowManager();
if (manageWindow) {
var radWindow = manageWindow.open(url, "<your_dialog_name>");
if (radWindow) {
radWindow.set_initialBehaviors(Telerik.Web.UI.WindowBehaviors.None);
radWindow.set_behaviors(Telerik.Web.UI.WindowBehaviors.Move + Telerik.Web.UI.WindowBehaviors.Close + Telerik.Web.UI.WindowBehaviors.Resize);
radWindow.setActive(true);
radWindow.SetModal(true);
radWindow.center();
radWindow.set_visibleStatusbar(false);
radWindow.set_keepInScreenBounds(true);
radWindow.set_minWidth(640);
radWindow.set_minHeight(480);
radWindow.setSize(640, 480);
radWindow.set_destroyOnClose(true);
radWindow.add_close(closeMyDialog);//after closing the RadWindow, closeMyDialog will be called
radWindow.argument = args;//you can pass the value from parent page to RadWindow dialog as this line
}
}
}
Closing the RadWindow dialog:
function closeMoveProjectDialog(sender, args) {
var objArgs = args.get_argument();
//objArgs variable stored the values returned from the RadWindow
//you can use it for your purpose
}
How to call this?
You can put the open method into your expected method. In my side, I have a method as shown below and I will call the RadWindow as this way:
function ShowForeignKeyFrontEditSingle(param1, param2){
var url = "ForeignKeyFrontEditSingle.aspx";
var objArgs = new Array();
objArgs[0] = param1;
objArgs[1] = param2;
openMyDialog(url, objArgs);
return;
}
Of course, you have to declare a RadWindowManager control
function GetRadWindowManager() {
return $find("<%=your_radwindow_manager_control.ClientID%>");
}
Take a look here, it explains how to use the ScriptManager.RegisterStartupScript method: http://www.telerik.com/help/aspnet-ajax/window-troubleshooting-javascript-from-server-side.html. Note it the ScriptManager's method. Also look at the Sys.Application.Load event to prevent your code from executing too early.