I'm trying to send new values to an HTML table after a page has already been rendered. New values are sent 'x minutes' after the page has already been rendered on the client end, and are displayed in a new column in the html table.
The HTML is created with C# code with the code behind file, and initiated via a function call inside the actual html on the aspx page.
htmlStr = "<tr><td>" + market[0].runners[marketCounter].runnerName + "</text></td>" + "<td>" + marketOdds[0].runners[marketCounter].lastPriceTraded.ToString() + "</td>" + "<td>" + "</td>" + "<td>" + NewValuesin10Mins()???????????????? + </td></tr>;
if you want to modify the client side after render, try to use the function RegisterStartupScript, the script block added by the RegisterStartupScript method executes when the page finishes loading but before the page's OnLoad event is raised
public String GetNewKey()
{
String _string_key = String.Empty;
Guid _guid = Guid.NewGuid();
foreach (char _char in Convert.ToBase64String(_guid.ToByteArray()))
{
_string_key += char.IsLetterOrDigit(_char) ? _char.ToString() : string.Empty;
}
return _string_key;
}
public void RunScript(String _script)
{
String function = #"<script type='text/javascript'> $(function () { " + _script + " }); </script>";
this.ClientScript.RegisterStartupScript(_page.GetType(), Utilities.GetNewKey(), function, false);
}
Related
I have a dropdownlist and a fileupload control in a panel which is added with other controls in an UpdatePanel. When a value is selected from the dropdown and a file is uploaded, the Upload button is enabled. For this I have a javascript function as follows:
function SetUploadButtonEnabled(controlPanel, fileUploadId) {
var docTypesList = controlPanel.find("select");
var gotListVal = docTypesList.val() != "";
var fileUpload = $find(fileUploadId);
var gotFileVal = fileUpload.getUploadedFiles().length > 0;
var enable = gotListVal && gotFileVal;
if (enable) {
controlPanel.find(".GxButtonBlue").removeAttr("disabled");
}
else {
controlPanel.find(".GxButtonBlue").attr("disabled", true);
}
}
I am trying to call it from code behind as follows, but the function is not being called:
string script = "<script type=\"text/javascript\">"
+ "\n $(document).ready(function (){"
+ "\n $(document).on(\"change\", \"#" + this._DdDocumentTypes.ClientID + "\", function(event){"
+ "\n var docUploadControlPanel = $(this).closest(\"#" + this._DocUploadControlPanel.ClientID + "\");"
+ "\n SetUploadButtonEnabled(docUploadControlPanel, \"" + this._fiInput.ClientID + "\");"
+ "\n });"
+ "\n });"
+ "\n "
+ "</script>";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "DocumentAjaxUploadCtrlScript_" + this.ClientID, script);
Since an Update Panel is there I even tried:
ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "DocumentAjaxUploadCtrlScript_" + this.ClientID, script, true);
Please help me find why the function is never called!
Here's one way to do it. The key here is the pageComponents object.
ASPX or User Control
<script>
var pageComponents = {
documentTypeSelector: "#<%= _DdDocumentTypes.ClientID %>",
uploadControlSelector: "#<%= _DocUploadControlPanel.ClientID %>",
fiInputSelector: "#<%= _fiInput.ClientID %>"
};
</script>
JavaScript Place after the above
function SetUploadButtonEnabled(controlPanel, fileUploadId) {
var docTypesList = controlPanel.find("select");
var gotListVal = docTypesList.val() != "";
var fileUpload = $find(fileUploadId);
var gotFileVal = fileUpload.getUploadedFiles().length > 0;
var enable = gotListVal && gotFileVal;
if (enable) {
controlPanel.find(".GxButtonBlue").removeAttr("disabled");
}
else {
controlPanel.find(".GxButtonBlue").attr("disabled", true);
}
}
$(document).ready(function (){
$(document).on("change", pageComponents.documentTypeSelector, function(event){
var docUploadControlPanel = $(this).closest(pageComponents.uploadControlSelector);
SetUploadButtonEnabled(docUploadControlPanel, pageComponents.fiInputSelector);
});
});
Remarks
You can avoid using the "bee sting" syntax above by setting the control ClientIDMode property to Static (assuming you're using only ASP.NET Page, not a user control. Then your JavaScript would look like below:
$(document).ready(function (){
$(document).on("change", "#documentType", function(event){
var docUploadControlPanel = $(this).closest("#uploadControl");
SetUploadButtonEnabled(docUploadControlPanel, "#fiInput");
});
});
In addition the line:
var docUploadControlPanel = $(this).closest(pageComponents.uploadControlSelector);
could be written as:
var docUploadControlPanel = $(pageComponents.uploadControlSelector);
since ClientID always returns a unique element ID for the entire page.
i am Adding multiple TextBoxes with Jquery in my Application, then in code behind file i want can access the values by Request.form[name]. I want to iterate these textboxes and read values of whatever Text is entered by the user, so i can store it in database.
any idea how can i save the value of these textboxes in Database spliting each textbox values by a Comma(,)
Please guide me how to get all these textbox values in loop and then save them in DB Table
$(document).ready(function () {
var counter = 2;
$(\"#addButton\").click(function () {
if (counter > 10) {
alert(\"Only 10 textboxes allow\");
return false;
}
var newTextBoxDiv = $(document.createElement('div'))
.attr(\"id\", 'TextBoxDiv' + counter);
newTextBoxDiv.html('<table><tr><td><input type=\"text\" name=\"textbox' + counter +
'\" id=\"textbox' + counter + '\" value=\"\" ></td><td><input type=\"text\" name=\"textbox' + counter +
'\" id=\"textbox' + counter + '\" value=\"\" ></td><td><input type=\"text\" name=\"textbox' + counter +
'\" id=\"textbox' + counter + '\" value=\"\" ></td></tr></table>');
newTextBoxDiv.appendTo(\"#TextBoxesGroup\");
return false;
counter++;
});
Probably you have do something like this, you could easily debug by using chrome debugger tool to retrieve all values from your input boxes.
$('table tr td').each(function() {
var values = "";
values = $(this).find('input').val() + ",";
});
I am using "Sharing" to send text (string) by email.
the data I am sharing is created like this:
string data = "Log Data\n" + "========\n";
data += "Log Type : " + log.LogType.ToString() + "\n";
data += "Date/Time: " + log.TimeStamp.ToString( "MM/dd/yy - HH:mm:ss" ) + "\n";
data += "Result: " + log.Result.ToString() + "\n";
data += "Value1: " + log.Value1 + " Value2: " + log.Value2 + "\n";
data += "Note: " + log.Note + "\n\n";
the data is prepared and sent in an email. However the "\n" is not interpreted correctly neither before I send (by the Windows 8 mail program) or the receiving side GMail.
The data presented on the send side looks like this:
Log Data ======== Log Type : ToDo Date/Time: 06/05/12 - 08:00:00 Result: Normal Value1: 170 Value2: 0 Note: note 1
The ShareTextHandler is like this:
DataRequest request = e.Request;
request.Data.Properties.Title = "Share Data: ";
request.Data.Properties.Description = "Send Data to an email address";
request.Data.SetText( data );
Was the "\n" changed in Windows 8? or the SetText does something to remove it?
EitanB
UPdate....
Hi,
Tried to do it with HTML:
Tried some test data with HTML like this:
private string PrepareShareData()
{
string CR = System.Environment.NewLine;
string data = string.Empty;
data += "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Final//EN\">" + CR;
data += "<html>" + CR;
data += "<body>" + CR;
data += "<p>" + CR;
data += "Log Data" + "<br/>" + CR;
data += "========" + "<br/>" + CR;
data += "Line 1" + "<br/>" + CR;
data += "Line 2" + "<br/>" + CR;
data += "<p>" + CR;
data += "</body>" + CR;
data += "</html>" + CR;
return data;
}
Did not work...
Tried also:
private string PrepareShareData()
{
string CR = System.Environment.NewLine;
string data = string.Empty;
data += "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Final//EN\">";
data += "<html>";
data += "<body>";
data += "<p>";
data += "Log Data" + "<br/>";
data += "========" + "<br/>";
data += "Line 1" + "<br/>";
data += "Line 2" + "<br/>";
data += "<p>";
data += "</body>";
data += "</html>";
return data;
}
did not work either....
I did create a .HTML file with the notepad that worked fine:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Final//EN">
<html>
<body>
<p>
Log Data<br/>
========<br/>
Line 1<br/>
Line 2<br/>
</p>
</body>
</html>
Is there a mail problem with HTML too or my HTML is wrong?
Thanks,
EitanB
Used:
var htmlFormat = Windows.ApplicationModel.DataTransfer.HtmlFormatHelper.CreateHtmlFormat( data );
request.Data.SetHtmlFormat( htmlFormat );
Where data is:
string data = string.Empty;
string BR = #"<br/>";
data += #"<html>";
data += #"<head><title>";
data += #"<title>";
data += #"Log Data<br/>";
data += #"========<br/>";
data += #"</title>";
data += #"</head>";
data += #"<body>";
data += #"Date/Time: " + log.TimeStamp.ToString( "MM/dd/yy - HH:mm:ss" ) + BR;
data += #"Note: " + log.Note + BR + BR;
data += #"</body>";
data += #"</html>";
too much work to go around Microsoft problem....
EitanB
try args.Request.Data.SetHtmlFormat(HtmlFormatHelper.CreateHtmlFormat(html));
Environment.Newline is certainly a step in the right direction, but I don't know if it will solve your problems.
This was an issue in the inbuilt mail app in Consumer Preview (and I haven't checked if it was fixed in RTM). I noticed that it didn't seem to want to respect line breaks. I confirmed that the correct data was being sent by writing a small dummy share target and ensuring that the text was rendered correctly and it was. Maybe you could send HTML in the share request - mail supports HTML as well as Text.
First of all as a general rule of thumb we should always be using a StringBuilder object to be appending strings together. The reason for this is: the string variable is immutable so every time we add a "+" sign we actually end up creating an entirely new instance of the string variable.
string data = string.Empty;
data += "Some Text Creates 1 variable";
data += "This creates a second variable" + "and this a third";
return data;
is better suited as
StringBuilder builder = new StringBuilder()
builder.Append("Some Text Creates 1 variable");
builder.Append("Since we havent yet created a string no 2nd variable is created");
builder.AppendLine("Should create a return before this line");
builder.AppendLine(Environment.NewLine);
builder.AppendLine("Should have an empty line above it");
return builder.ToString();
// only creates 1 string variable
Or you could wrap the single variable in the HTML Encode method described
return System.Net.WebUtillity.UrlEncode(builder.ToString());
How to show annotation present in an entity in popup window by using html web resource. My requirement is to display annotation present in an entity in a popup window and in popup window user should be able to delete , upload and convert the annotation to pdf (if he wants). Can you suggest a best method to achieve this in crm 2011.
function retann() {
//debugger;
var serverUrl = Xrm.Page.context.getServerUrl();
var GUIDvalue = Xrm.Page.data.entity.getId();
// Creating the Odata Endpoint
var oDataPath = "http://url/organization/XRMServices/2011/OrganizationData.svc/";
var retrieveReq = new XMLHttpRequest();
var Odata = oDataPath + "/AnnotationSet?$select=DocumentBody,FileName,MimeType,ObjectId&$filter=ObjectId/Id eq guid'" + GUIDvalue + "'";
retrieveReq.open("GET", Odata, false);
retrieveReq.setRequestHeader("Accept", "application/json");
retrieveReq.setRequestHeader("Content-Type", "application/json; charset=utf-8");
retrieveReq.onreadystatechange = function () { retrieveReqCallBack(this); };
retrieveReq.send();
}
function retrieveReqCallBack(retrieveReq) {
if (retrieveReq.readyState == 4 /* complete */) {
//debugger;
var retrieved = this.parent.JSON.parse(retrieveReq.responseText).d;
var message = "";
var fun_var =
"<script type=text/javascript>" +
"function result_value()" +
"{" +
"var rad_val;" +
"for (var i=0; i < document.orderform.test.length; ++i){if (document.orderform.test[i].checked){rad_val = document.orderform.test[i].value;}}" +
"if(rad_val==null || rad_val=='')" +
"{" +
"window.top.opener.Xrm.Page.data.entity.attributes.get('new_radiovalue').setValue('0');" +
"}" +
"else" +
"{" +
"window.top.opener.Xrm.Page.data.entity.attributes.get('new_radiovalue').setValue(rad_val);" +
"}" +
" window.top.opener.Xrm.Page.data.entity.attributes.get('new_fireplugin').setValue(1);" +
"window.top.opener.Xrm.Page.data.entity.save();" +
"this.window.close();" +
"}" +
"function result_value1()" +
"{" +
"var rad_val1;" +
"for (var i=0; i < document.orderform.test.length; ++i){if (document.orderform.test[i].checked){rad_val1 = document.orderform.test[i].value;}}" +
"if(rad_val1==null || rad_val1=='')" +
"{" +
"window.top.opener.Xrm.Page.data.entity.attributes.get('new_radiovalue').setValue('0');" +
"}" +
"else" +
"{" +
"window.top.opener.Xrm.Page.data.entity.attributes.get('new_radiovalue').setValue(rad_val1);" +
"}" +
" window.top.opener.Xrm.Page.data.entity.attributes.get('new_delete').setValue(1);" +
"window.top.opener.Xrm.Page.data.entity.save();" +
"this.window.close();" +
"}" +
"</script>";
var n = retrieved.results.length;
for (var i = 0; i < retrieved.results.length; i++) {
message += " <input type='radio' name='test' value=' " + i + "' />" + retrieved.results[i].FileName + "<br />";
}
myWindow = window.open('', '', 'width=500,height=150,left=250,top=250,scrollbars=yes,resizable=yes,directories=yes');
myWindow.document.write(fun_var + "<body bgcolor=GhostWhite style='font-family:verdana;font-size:11px;'><form name='orderform' style='font-family:verdana;font-size:11px;'>" + message + "</br><center ><input type='button' onclick='result_value()' style='font-family:verdana;font-size:11px;' value='Convert To PDF'/></center>" + "</form>");
myWindow.focus();
}
}
function SetField() {
var AddressType = Xrm.Page.data.entity.attributes.get("new_radiovalue");
AddressType.setValue("");
}
function save_form() {
// var MainPhone = Xrm.Page.data.entity.attributes.get("new_name").getValue();
//Xrm.Page.data.entity.attributes.get("new_name").setValue(MainPhone+".");
Xrm.Page.data.entity.save();
}
retrieveReqCallBack(this) function displays the popup with annoatation. Using the above code i'm able to convert doc to pdf. Since i want to add multiple functionalities like upload , delete and convert to pdf. If annotation is present then popup should have option to upload and if annotation is present then it has to show delete and convert to pdf buttons.
I found this as solution to my question,
You'll need to create a custom web resource (html) with javascript to pull the data out of the sub-grid, parse the rows, query the crm data via REST or SOAP to see if there is an annotation, then put an icon of the 'paperclip' which'll allow users to upload attachments against that record.
I have dynamicly added html elements(selectlists) in a form :
//Dynamicly adding selectlist elements
function newshit() {
i = i + 1
$("#mytable").append("<tr><td><div id='div" + i + "'><select id='elem" + i + "' name='elem" + i + "' class='ted'></select><input type='button' value='-' id='buttonminus" + i + "' style='width:5%;' onclick='removeelem(elem" + i + ",buttonminus" + i + "," + i + ")'/></div></td></tr>")
getitems("elem" + i)
}
//filling lists
function getitems(item) {
$.getJSON('#Url.Content("~/Stok/Items/")', {}, function (data) {
$.each(data, function (i, c) {
$("#" + item).append("<option value='" + c.Value + "' title='" + c.Text + "' label='" + c.Text + "'>" + c.Text + "</option>")
})
})
}
//removing element, when button next to it used
function removeelem(elem,buttonminus,i) {
if ($("select").length > 1) {
$("#div" + i).closest('tr').empty().remove()
} else if ($("select").length <= 1) {
alert("At least 1 of items must be chosen to create a group!")
}
}
//checking elements and values existence
function check() {
var slcts = $("select").serialize();
alert(slcts)
}
im trying to get the value of each selectlist's selected option value and put them into an array than send them to my controller on form submit.
How can i achive this?
Need to check this, but I think that the following should work:
Change your code so that the format of your ids is something like:
id="elem[0]"
Then if your controller has a signature something like this:
public ActionResult Something(IEnumerable<string> elem)
{
}
Then his should "just work".
You could use something like -
var selectdata = $("select").serialize()
This will return a string in the form <select name attribute1>=<chosen value1>&<select name attribute2>=<chosen value2> etc. You'd need to add a 'name' attribute to your select HTML when you create it for this to work.
Demo - http://jsfiddle.net/ipr101/fZXha/
You could then put the selectdata variable in a hidden field before the form was posted or send it via AJAX using the ajax or post methods.