EDIT: I added in the hf from the first reply that was pointed out. This helped with a few other issues, but still did not fix the problem.
I am trying to bind a list to a gridview with a LOT of hidden fields (I'll only use 2 of the 50) for temporary holding so the user can create and delete multiple items without going back and forth to the database multiple times during creation. I'm fine with binding to and recalling from the BoundFields; however, when I try to recall the hidden field values it comes back as null. I may be having problems with the binding to the hidden fields. Here's my code
ASP:
<asp:GridView ID="grdOtherCarrier" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundField HeaderText="Sequence" DataField="Sequence"></asp:BoundField>
<asp:BoundField HeaderText="Pay ID" DataField="PayID"></asp:BoundField>
<asp:BoundField HeaderText="Provider" DataField="Provider"></asp:BoundField>
<asp:TemplateField HeaderText="Actions">
<ItemTemplate>
<asp:HiddenField ID="hfInsuredLastName" Value="<%#Eval("InsuredLastName")%>" runat="server" />
<asp:HiddenField ID="hfInsuredFirstName" Value="<%#Eval("InsuredFirstName")%>" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
C# / code behind:
protected void lblSubmitOtherCarrier_Click(object sender, EventArgs e)
{
List<OtherCarrier> OCList = new List<OtherCarrier>();
OtherCarrier OC;
foreach (GridViewRow row in grdOtherCarrier.Rows)
{
if (row.RowType == DataControlRowType.DataRow)
{
OC = new OtherCarrier();
String Sequence = row.Cells[0].Text.ToString() ; // primary value
String PayID = row.Cells[1].Text.ToString(); // primary value
String Provider = row.Cells[2].Text.ToString(); // primary value
HiddenField InsuredLastName = (HiddenField)row.FindControl("hfInsuredLastName");
HiddenField InsuredFirstName = (HiddenField)row.FindControl("hfInsuredFirstName");
OC.Sequence = Sequence;
OC.PayID = PayID;
OC.Provider = Provider;
OC.InsuredLastname = InsuredLastName.Value.ToString();
OC.InsuredFirstName = InsuredFirstName.Value.ToString();
OCList.Add(OC);
}
}
OC = new OtherCarrier();
OC.Sequence = txtSequence.Text;
OC.PayID = txtPayID.Text;
OC.Provider = txtProvider.Text;
OC.InsuredLastname = txtInsuredLastname.Text;
OC.InsuredFirstName = txtInsuredFirstName.Text;
OCList.Add(OC);
TD.OtherCarrierList = OCList;
grdOtherCarrier.DataSource = OCList;
grdOtherCarrier.DataBind();
mpeAddOtherCarrier.Hide();
txtSequenceNo.Text = (grdOtherCarrier.Rows.Count + 1).ToString();
}
When it gets to assigning the OC.InsuredLastname from the hidden field the hidden field is coming up as null value. Either I'm not reading it correctly or it's not being written correctly.
so...
you are trying to find a control as
(HiddenField)row.FindControl("InsuredLastName");
as you can see, named InsuredLastName when you explicit say in the HTML that your control name is:
<asp:HiddenField
ID="hfInsuredLastName"
Value="<%#Eval("InsuredLastName")%>"
runat="server" />
named hfInsuredLastName
all you need to do is change the call to
(HiddenField)row.FindControl("hfInsuredLastName")
Related
I have to dynamically generate the rows in Docusign template's table. Is there a way to achieve that ? I have to mention customer's detail which can vary from contract to contract and for that i don't want to keep static placeholders for that such that I preconfigure 100 rows and it will populate accordingly.
Your problem will be solved using tab from docusign official docs. Also please read examples here. API ref about envelops will also helps you. Further demonstrations will be following.
function document1(args) {
return (
<div>
<table style="width:100%">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>{args.firstName}</td>
<td>{args.lastName}</td>
<td>{args.age}</td>
</tr>
</table>
</div>
);
}
use that document into makeEnvelope function.
function makeEnvelope(args) {
// create the envelope definition
let env = new docusign.EnvelopeDefinition();
env.emailSubject = "Please sign this document set";
// add the documents
let doc1 = new docusign.Document();
let doc1b64 = Buffer.from(document1(args)).toString("base64");
doc1.documentBase64 = doc1b64;
doc1.name = "YOUR markup doc name";
doc1.fileExtension = "html";
doc1.documentId = "1";
// The order in the docs array determines the order in the envelope
env.documents = [doc1];
// create a signer recipient to sign the document, identified by name and email
// We're setting the parameters via the object constructor
let signer1 = docusign.Signer.constructFromObject({
email: args.signerEmail,
name: args.signerName,
recipientId: "1",
routingOrder: "1",
});
// routingOrder (lower means earlier) determines the order of deliveries
// to the recipients. Parallel routing order is supported by using the
// same integer as the order for two or more recipients.
// create a cc recipient to receive a copy of the documents, identified by name and email
// We're setting the parameters via setters
let cc1 = new docusign.CarbonCopy();
cc1.email = args.ccEmail;
cc1.name = args.ccName;
cc1.routingOrder = "2";
cc1.recipientId = "2";
// Create signHere fields (also known as tabs) on the documents,
// We're using anchor (autoPlace) positioning
//
// The DocuSign platform searches throughout your envelope's
// documents for matching anchor strings. So the
// signHere2 tab will be used in both document 2 and 3 since they
// use the same anchor string for their "signer 1" tabs.
let signHere1 = docusign.SignHere.constructFromObject({
anchorString: "**signature_1**",
anchorYOffset: "10",
anchorUnits: "pixels",
anchorXOffset: "20",
}),
signHere2 = docusign.SignHere.constructFromObject({
anchorString: "/sn1/",
anchorYOffset: "10",
anchorUnits: "pixels",
anchorXOffset: "20",
});
// Tabs are set per recipient / signer
let signer1Tabs = docusign.Tabs.constructFromObject({
signHereTabs: [signHere1, signHere2],
});
signer1.tabs = signer1Tabs;
// Add the recipients to the envelope object
let recipients = docusign.Recipients.constructFromObject({
signers: [signer1],
carbonCopies: [cc1],
});
env.recipients = recipients;
// Request that the envelope be sent by setting |status| to "sent".
// To request that the envelope be created as a draft, set to "created"
env.status = args.status;
return env;
}
then make example worker function to use that envelope containing documents(either your table data or something else)
exampleSigningViaEmail.worker = async (args) => {
// Data for this method
// args.basePath
// args.accessToken
// args.accountId
let dsApiClient = new docusign.ApiClient();
dsApiClient.setBasePath(args.basePath);
dsApiClient.addDefaultHeader("Authorization", "Bearer " + args.accessToken);
let envelopesApi = new docusign.EnvelopesApi(dsApiClient),
results = null;
// Step 1. Make the envelope request body
let envelope = makeEnvelope(args.envelopeArgs);
// Step 2. call Envelopes::create API method
// Exceptions will be caught by the calling function
results = await envelopesApi.createEnvelope(args.accountId, {
envelopeDefinition: envelope,
});
let envelopeId = results.envelopeId;
console.log(`Envelope was created. EnvelopeId ${envelopeId}`);
return { envelopeId: envelopeId };
};
The front end (html and css) is set up such a way that for the description text from a Sitecore content field needs to have a <p> tag wrapped around it.
So by default the RTE wraps texts in a <p> tag = TRUE. BUT the catch is you will need to hit Enter or copy/paste multiple paragraphs.
How can we force Sitecore to add a P tag if it's just one line?
Fortunately, From the dll, one particular function caught my eye:
protected virtual void SetupScripts()
{
foreach (XmlNode node in Factory.GetConfigNodes("clientscripts/htmleditor/script"))
this.Result.Scripts.AppendFormat("<script src=\"{0}\" language=\"{1}\"></script>\n", (object) XmlUtil.GetAttribute("src", node), (object) XmlUtil.GetAttribute("language", node));
}
NICE, eh? The developers of SITECORE are clever after all.
So I did this in the web.config,
<!— CLIENT SCRIPTS
These script files are included in the client, e.g. '<script src="/myscript.js" language="JavaScript"/>'
—>
<clientscripts>
<everypage />
<htmleditor>
<script src=”/assets/js/CustomRTE.js” language=”javascript”/>
</htmleditor>
</clientscripts>
And overrode scSendRequest function from EditorWindow.aspx.
window.scSendRequest = function(evt, command) {
var editor = scRichText.getEditor();
if (editor.get_mode() == 2) { //If in HTML edit mode
editor.set_mode(1); //Set mode to Design
}
var htmls = editor.get_html(true);
var regex = /<p[^>]*>.*?<\/p>/i;
var match = regex.exec(htmls);
if(match == null && htmls != null) {
htmls = "<p>" + htmls + "</p>";
}
//$("EditorValue").value = editor.get_html(true);
$("EditorValue").value = htmls;
scForm.browser.clearEvent(evt);
scForm.postRequest("", "", "", command);
return false;
}
AND YAY .. double rainbow and unicorn.
You could create your own custom solution for this requirement as well.
You could create a new pipeline event in the
<saveRichTextContent> pipeline - This could enable you to append the tag when you hit save on the rich text editor in sitecore
<renderField> pipeline - This could on the fly wrap your text into <p></p> tags while rendering the page, if the tag was not there in the original rtf text.
If you go for method 1: <saveRichTextContent>
You could add to the pipeline in web.config:
<processor type="Sitecore72.Classes.WrapRichTextInParagraphOnSave, Sitecore72" />
And you could use the following corresponding code:
namespace Sitecore72.Classes
{
public class WrapRichTextInParagraphOnSave
{
public void Process(SaveRichTextContentArgs args)
{
if (!(args.Content.Trim().StartsWith("<p>") && args.Content.Trim().EndsWith("</p>")))
args.Content = "<p>" + args.Content + "</p>";
}
}
}
Please note, that this pipeline gets triggered only when you use the Show Editor buttong of a rich text field:
If you go for method 2: <renderField>
To append to this pipeline you would use this config:
<processor type="Sitecore72.Classes.WrapRichTextInParagraphOnRender, Sitecore72" />
And you could use the following corresponding code:
namespace Sitecore72.Classes
{
public class WrapRichTextInParagraphOnRender
{
public void Process(RenderFieldArgs args)
{
if (args.FieldTypeKey == "rich text" && !(args.Result.FirstPart.Trim().StartsWith("<p>") && args.Result.FirstPart.Trim().EndsWith("</p>")))
args.Result.FirstPart = "<p>" + args.Result.FirstPart + "</p>";
}
}
}
For both these, ensure you add reference to Sitecore.Kernel.dll and HtmlAgilityPack.dll. Both of these are available with the sitecore package solution.
I have 3 radio buttons which when selected, will run different query.
I have no idea how the if-else condition works for grails radio buttons as I'm completely new to grails..
this is my gsp page.
<label>Search id:</label><input type = "text" name = "searchid1">
<input type ="submit" name ="search" value ="Go!">
<br>
<g:radio name="myGroup" value="input1"/>
<g:radio name="myGroup" value="input2"/>
<g:radio name="myGroup" value="input3"/>
and the queries at the controller site..
String searchQ1 = "select * from alert_list where id = " + params.searchid1
def searchit1 = sql.rows(searchQ1)
String searchQ2 = "select * from Admin where id = " + params.searchid1
def searchit2 = sql.rows(searchQ2)
String searchQ3 = "select * from sec_user where id = " + params.searchid1
def searchit3 = sql.rows(searchQ3)
[searchit1: searchit1, searchit2: searchit2, searchit3: searchit3]
the method you're using for GSP is correct. However, in the controller you need to add in IF-ELSE statement.
if (request.getParameter("myGroup").equals("input1"))
{
println("duck")
redirect (action: radio)
}
if (request.getParameter("myGroup").equals("input2"))
{
println("chicken")
redirect (action: abc)
}
Add the if-else condition in your controller and your problem will be fixed.
I need to get the primary key for a row and then insert it into one of the other columns in a string.
So I've tried to do it something like this:
newsObj = new news();
newsObj.name = "test"
newsObj.Save();
newsObj.url = String.Format("blah.aspx?p={0}",newsObj.col_id);
newsObj.Save();
But it doesn't treat it as the same data object so newsObj.col_id always comes back as a zero. Is there another way of doing this? I tried this on another page and to get it to work I had to set newsObj.SetIsLoaded(true);
This is the actual block of code:
page p;
if (pageId > 0)
p = new page(ps => ps.page_id == pageId);
else
p = new page();
if (publish)
p.page_published = 1;
if (User.IsInRole("administrator"))
p.page_approved = 1;
p.page_section = staticParent.page_section;
p.page_name = PageName.Text;
p.page_parent = parentPageId;
p.page_last_modified_date = DateTime.Now;
p.page_last_modified_by = (Guid)Membership.GetUser().ProviderUserKey;
p.Add();
string urlString = String.Empty;
if (parentPageId > 0)
{
urlString = Regex.Replace(staticParent.page_url, "(.aspx).*$", "$1"); // We just want the static page URL (blah.aspx)
p.page_url = String.Format("{0}?p={1}", urlString, p.page_id);
}
p.Save();
If I hover the p.Save(); I can see the correct values in the object but the DB is never updated and there is no exception.
Thanks!
I faced the same problem with that :
po oPo = new po();
oPo.name ="test";
oPo.save(); //till now it works.
oPo.name = "test2";
oPo.save(); //not really working, it's not saving the data since isLoaded is set to false
and the columns are not considered dirty.
it's a bug in the ActiveRecord.tt for version 3.0.0.3.
In the method public void Add(IDataProvider provider)
immediately after SetIsNew(false);
there should be : SetIsLoaded(true);
the reason why the save is not working the second time is because the object can't get dirty if it is not loaded. By adding the SetIsLoaded(true) in the ActiveRecord.tt, when you are going to do run custom tool, it's gonna regenerate the .cs perfectly.
I have ig:TemplateDataField that contains label.
In InitializeRow event handler I try to find that label with e.Row.FindControl but I get null.
I was not able to find another way to find my label.
How to look for controls in WebDataGrid rows during InitializeRow event?
You have to specify the column that you want to search in like e.Row.Items[0].FindControl("ControlID") where 0 the column index.
Below is a solution that should work.
note: Code is for an Infragistics UltraWebGrid control. The WebDataGrid control is the UltraWebGrid's successor.
C#:
protected void UltraWebGridCustomers_InitializeRow(object sender, Infragistics.WebUI.UltraWebGrid.RowEventArgs e)
{
TemplatedColumn col = (TemplatedColumn)e.Row.Cells.FromKey("HyperLinkEmailColumn").Column;
CellItem cellItem = (CellItem)col.CellItems(e.Row.Index);
HyperLink hyperLinkEmail = (HyperLink)cellItem.FindControl("HyperLinkSendEmail");
hyperLinkShowDetails.Attributes.Add("onclick", "alert('This is the email link');");
}
VB.NET:
Private Sub UltraWebGridCustomers_InitializeRow(ByVal sender As Object, ByVal e As Infragistics.WebUI.UltraWebGrid.RowEventArgs) Handles UltraWebGridCustomers.InitializeRow
Dim col As TemplatedColumn = CType(e.Row.Cells.FromKey("HyperLinkEmailColumn").Column, TemplatedColumn)
Dim cellItem As CellItem = CType(col.CellItems(e.Row.Index), CellItem)
Dim hyperLinkEmail As HyperLink = CType(cellItem.FindControl("HyperLinkSendEmail"), HyperLink)
hyperLinkShowDetails.Attributes.Add("onclick", "alert('This is the email link');")
End Sub
Aspx code:
<infragistics:UltraWebGrid ID="UltraWebGridCustomers" runat="server">
<Bands>
<infragistics:UltraGridBand BaseTableName="Customers" Key="BandCustomers">
<Columns>
...
<infragistics:UltraGridColumn Key="NameColumn" BaseColumnName="Name" IsBound="True">
<Header Caption="Name">
</Header>
</infragistics:UltraGridColumn>
<infragistics:UltraGridColumn Key="EmailColumn" BaseColumnName="Email" IsBound="True">
<Header Caption="Email Address">
</Header>
</infragistics:UltraGridColumn>
<infragistics:TemplatedColumn Key="HyperLinkEmailColumn">
<CellTemplate>
<asp:HyperLink ID="HyperLinkSendEmail" NavigateUrl='<%# "~/EmailForm.aspx?email=" & DataBinder.Eval(Container.DataItem,"Email")%>' ToolTip="Send Email" runat="server" />
</CellTemplate>
</infragistics:TemplatedColumn>
...
</Columns>
<AddNewRow View="NotSet" Visible="NotSet">
</AddNewRow>
</infragistics:UltraGridBand>
</Bands>
...
</infragistics:UltraWebGrid>