I am having a parent control and a child control in DNN.
When i try to get moduleId on page load event of child control i get -1.
Below is the code on child control.
Globals.NavigateURL(PortalSettings.ActiveTab.TabID, "PlanSponsorManager", "mid=" + ModuleId);
Please Advice how can i get the moduleId
When you load the child control you need to do something like the following
var controlToLoad = "Controls/ArticleList.ascx";
if (ArticleId > 0)
{
controlToLoad = "Controls/ArticleView.ascx";
}
var mbl = (dnnsimplearticleModuleBase)LoadControl(controlToLoad);
mbl.ModuleConfiguration = ModuleConfiguration;
mbl.ID = System.IO.Path.GetFileNameWithoutExtension(controlToLoad);
phViewControl.Controls.Add(mbl);
Setting the module configuration is important
Example from http://dnnsimplearticle.codeplex.com/SourceControl/latest#cs/View.ascx.cs
I suppose your child control inherits from PortalModuleBase. Nevertheless, I believe that using ModuleId property of such a type of control returns -1 because it's not a declared control in the extension database.
I think you could try to get the parent PortalModuleBase using "Parent.ModuleID".
Related
I have a form with customer info that needs to be processed one transaction per page. I'm using the binding navigator to manage my pagination.
It works in all but some cases. In the cases where it doesn't work, I have to open a different window to look up information and return it to the main form. Here is the code for that:
// save current work
updateDataTable();
// Open a window and get new customer info
// CurrentCustomer is returned from the opened window
using (SqlConnection cx = new SqlConnection(GetConnectionString()))
{
DataRowView dataRow = (DataRowView)procBindingSource.Current;
dataRow.BeginEdit();
dataRow["CUSTOMER"] = CurrentCustomer;
dataRow.EndEdit();
updateDataItems();
SqlCommand cmd = new SqlCommand(
#" select acct_no from cust_processing where id = #id ", cx);
cmd.Parameters.AddWithValue("#id", (int)dataRow["ID"]);
cx.Open();
var results = cmd.ExecuteScalar();
if (results != null)
{
dataRow.BeginEdit();
dataRow["ACCT_NO"] = results.ToString();
dataRow.EndEdit();
updateDataItems(); <------ CONCURRENCY ERROR
}
}
The error I am getting is a concurrency error. I think that I have more than one version of the row possibly ? I thought I was making sure that I was on the most recent version of the row by calling updateDataTable(). I am the only user so I know I am creating the problem myself.
Here is my update method which is called when I change pages or save and exit or want to write the commit the data:
void updateDataItems()
{
this.procBindingSource.EndEdit();
this.procTableAdapter.Update(xyzDataSet);
xyzDataSet.AcceptChanges();
}
I have tried executing updateDataItems from various places such as after I assign dataRow["ACCT_NO"] = results.ToString() or before and after assigning that.
I'm pretty much down to guess and check so any thoughts, help and advice will be appreciated and +1.
Okay -- so the problem was that I was trying to update the current row from the program and also using the binding navigator. They were not working together properly.
The solution was to add a text box to the form in the forms designer and set visible = false and bind it to ACCT_NO. Once I got the results from my other form, I just needed to set the .text property of the ACCT_NO textbox to the new value and the binding navigator managed all my updates for me correctly.
txtAcct_No.text = results.ToString();
I want to execute a data control operation (CreateInsert and Delete) from a buttons ActionListener. I am aware a data control button can be inserted from the Data Controls menu, but for various reasons I need to do it this way, a prominent one being I need to perform extra runtime checks.
I found the following code:
OperationBinding operation = bindings.getOperationBinding("operation_name");
operation.getParamsMap().put("parameter_name", parameterValue);
operation.execute();
But don't know which variables to use for myself. First of all, I don't know which binding I should use. Then, the operation name should, as far as I know, be CreateInsert, and for the next button, CreateInsert1. Thats whats used for UIBinding now (which I will remove).
The Data control I want to use the operation of is 'ARNG1'.
So in short, I need to know how to manually invoke this Data control's CreateInsert operation.
Thanks in advance.
See if this will help you:
https://blogs.oracle.com/shay/entry/doing_two_declarative_operatio
the code you want to execute an operation behind a actionlistener:
public BindingContainer getBindings() {
if (this.bindings == null) {
FacesContext fc = FacesContext.getCurrentInstance();
this.bindings = (BindingContainer)fc.getApplication().
evaluateExpressionGet(fc, "#{bindings}", BindingContainer.class);
}
return this.bindings;
}
BindingContainer bindings = getBindings();
OperationBinding operationBinding =
bindings.getOperationBinding("doQueryResultReset");
operationBinding.execute();
Similar to Joe's answer but does not use EL Expression evaluator and uses direct access instead to get the BindingContainer
//Get binding container
BindingContainer bindings = BindingContext.getCurrent().getCurrentBindingsEntry();
// get an Action or MethodAction
OperationBinding method = bindings.getOperationBinding("methodAction");
method.execute();
List errors = method.getErrors();
I am using db.Key.from_path(Model, key_name) in several different places in my code and then call either db.get() or Model.get_by_key_name(). I noticed that these latter commands were always returning 0 items even though I knew for sure I should be getting something back. Upon closer inspection, I noticed that the db.Key.from_path() command was not returning the correct key. The key returned looks very similar, especially at the beginning, but some of the characters are different and it is about 75% shorter than the key shown in the datastore viewer. Has anyone else encountered this? Thanks.
Here is some sample code:
class Root(db.Model):
pass
class Parent(db.Model):
pass
class MyModel(db.Model):
pass
root = Root().put()
parent = Parent(key_name=parentname,parent=root).put()
mymodel = MyModel(key_name=mymodelname,parent=parent).put()
mymodel_k = db.Key.from_path('Parent','parentname','MyModel','mymodelname')
mymodel = db.get(mymodel_k)
mymodel is None
you are not constructing the path correctly with all the ancestors.
root = Root().put()
parent = Parent(key_name=parentname, parent=root).put()
mymodel = MyModel(key_name=mymodelname, parent=parent).put()
Root -> has no parents
Parent -> has parent Root
MyModel -> has parent Parent
db.Key.from_path('Parent','parentname','MyModel','mymodelname')
this one misses the Root ancestor which is contained in the Parent Key.
the right key would be:
db.Key.from_path('MyModel', 'mymodelname', parent=parent)
and this is why they key you create is shorter! one ancestor is missing.
It looks like there are two ancestor levels, so you should use this:
Key.from_path('Root', root.key().id(), 'Parent','parentname','MyModel','mymodelname')
or
Key.from_path('Parent','parentname','MyModel','mymodelname', parent=root)
I am trying to manipulate a requested document in the WPF WebBrowser-control. I already managed it to invoke JavaScript on loaded document, but I am not able to change the shown HTML-code in the control itself.
My (very simplified) code in the OnNavigating-Handler looks like this:
mshtml.HTMLDocument doc = (mshtml.HTMLDocument)View.browser.Document;
HTMLTableClass table = doc.getElementById("someTable") as HTMLTableClass;
if (table != null)
{
table.appendChild((IHTMLDOMNode)(doc.createElement("<tr>") as IHTMLElement));
}
doc.close();
The -element doesn't get appended to displayed document in the control.
Any hints are very appreciated!
I finally got it. Its only possible to change the content of the table by adding rows and cells which i wanted to avoid in first place. My approach was to directly change the content of the -tag, which didnt work.
mshtml.IHTMLTableRow row = table.IHTMLTable_insertRow(-1) as mshtml.IHTMLTableRow;
mshtml.IHTMLElement c = (mshtml.IHTMLElement)row.insertCell(0);
c.innerText = "some";
mshtml.IHTMLElement c1 = (mshtml.IHTMLElement)row.insertCell(1);
c1.innerText = "text";
I am building an iGoogle like "dashboard" for our application with silverlight 4.
Each users dashboard (which snapins and their positions) will be stored in the database. Each snap in is a user control, for example... AwesomeSnapin.xaml.
On the dashboard page in silverlight I am retrieving the users dashboard which is a collection of snapin objects which include the information on the snapin. I can store the name of the page or the class or whatever is needed.
I have the following code which loops through the collection of snapins to add them to the dashboard page. In testing I have just hard coded a single snapin item. Here is the prototype code:
foreach (var UserSnapin in op.Entities)
{
UserControl uc = new AmsiSL.eFinancials.BudgetCheck();
Canvas.SetLeft(uc, UserSnapin.PositionLeft);
Canvas.SetTop(uc, UserSnapin.PositionTop);
Layout.Children.Add(uc);
MessageBox.Show(String.Format("Added {0}",UserSnapin.Snapin.Name));
}
The above works fine... but of course adds the BudgetCheck snapin for every item that is defined for the users dashboard. Of course the messagebox is for debugging purposes only.
How would I change line 3 of that to load the user control class (using classname or xaml path whichever is better) based on the data in the collection.
I'll assume for the moment that UserSnapin.Snapin.Name in this case is "BudgetCheck" and that all Snapins are found in the AmsiSL.eFinancials namespace. I'll also assume that your Usercontrols are compilied in to the same application assembly. You can use this code:-
foreach (var UserSnapin in op.Entities)
{
Type snapInType = Assembly.GetExecutingAssembly()
.GetType("AmsiSL.eFinancials." + UserSnapin.Snapin.Name);
UIElement snapIn = (UIElement)Activator.CreateInstance(snapInType );
Canvas.SetLeft(snapIn , UserSnapin.PositionLeft);
Canvas.SetTop(snapIn , UserSnapin.PositionTop);
Layout.Children.Add(snapIn);
}
IF the snapins are an a library instead you can probably use the Type.GetType(string) static method to resolve the value for snapInType but you would need to know the assembly name as well.