Following is my code
-- the .aspx file
<div id="testDiv" runat="server"></div>
-- the .aspx.cs file
Literal lit1 = new Literal();
lit1.Text = "<table class='allocTable'>";
lit1.Text += "<tr><td><input type='text' runat='server' id='testbox1'></input></td></tr>";
... some other controls <tr><td>...
lit1.Text += "</table>"
testDiv.Controls.Add(lit1);
Now how can I find testbox1 in the .aspx.cs file? I have used FindControl on testDiv and the placeHolder but it returns null.
It seems the textboxes have not been added to the page control but they have just been rendered.
If you want to get the value of the textbox on post back, you could use Request.Form["testbox1"].
If you want wo work with "real" server controls, you would use an asp:Panel in your aspx file instead of your div.
In the asp.cs Init or Load method you would then add an HtmlTable to the Panel.Controls collection, HtmlTableRow(s) to the HtmlTable.Rows collection and HtmlTableCell(s) to the HtmlTableRow.Cells collection.
As you create the input controls you are adding to the Cell.Controls collection, you can store them in private member variables.
Related
I've one grid created on second page of page frame and linked to .PRG file for each time activate on different page. Under Activate events, each grid's column defined its own member class created under .PRG file.The problem is I couldn't able to access to each member control of grid's columns even I tried to change it but it will remain same class created under individual page's activate events.
I won't initialise the gird's column control base class on grid's init event because I need to set additive access to different .PRG file When access on different page. This problem of failed to access column member or control of grid won't be exists in form when I initalised grid's member control under grid's init events. BTW,i'm using vfp 6.
My Code under Page item Activate Events
set procedure to
set procedure to cn_pro additive
for count = thisform.page_.pages(thisform.page_.activepage).grid_list.columncount to 1 step -1
column_ = "column" + alltrim(str(count))
thisform.page_.pages( thisform.page_.activepage ).grid_list.removeobject( "&column_")
next
with thisform.page_.pages(thisform.page_.activepage).grid_list
.addobject("column1","column")
.columns(1).visible = .t.
.columns(1).bound = .t.
.columns(1).width = 75
.columns(1).header1.alignment = 2
.columns(1).header1.caption = "Mod_Qty"
.columns(1).removeobject("text1")
.columns(1).addobject("btn_qty","btn_quan")
.columns(1).currentcontrol = "btn_qty"
.columns(1).btn_qty.visible = .t.
.columns(1).btn_qty.caption = "Mod Qty"
.columns(1).sparse = .f.
endwith
create cursor tmpcur(btn_qty logical null)
use in select('tmpcur')
use in dbf('tmpcur') in 0 again alias tmpcur_
use in tmpcur
thisform.page_.pages(thisform.page_.activepage).grid_list.recordsource = ""
thisform.page_.pages(thisform.page_.activepage).grid_list.recordsource = "tmpcur_"
thisform.page_.pages(thisform.page_.activepage).grid_list.refresh()
**My class code in cn_pro.PRG file(Same example 1 problem)**
define class frm as form
procedure keypress
LPARAMETERS nKeyCode, nShiftAltCtrl
for each frm_ in _screen.forms
if alltrim(frm_.name) == "MAIN"
scan
with frm_.page_.pages( frm_.page_.activepage ).grid_list
**=>Example is here I've two record inside the grid,
**=>I want to change the property of button or access on it.**
.column1.btn_qty.enabled = .f.
**=>It will return Error message said "unknown member btn_qty" How to fix it?**
endwith
endscan
endif
endfor
endpro
enddefine
**My class code in cn_pro.PRG file(Same example 2 problem)**
define class frm as form
procedure keypress
LPARAMETERS nKeyCode, nShiftAltCtrl
for each frm_ in _screen.forms
if alltrim(frm_.name) == "MAIN"
scan
with frm_.page_.pages(frm_.page_.activepage).grid_list
**=>Example is here I've two record inside the grid,
**=>I want to change the property of button or access on it.**
.removeobject('column1')
**=>Remove entire column1 contained with** commandbutton "btn_qty"
.createobject('column1','column')
.column1.bound = .t.
.column1.text1.visible = .t.
.column1.sparse = .f.
.refresh()
**=> Previous CommandButton on column1 should be changed and
** replace with text here but It won't change and still be
** same commandbutton.Why, How to fix it?**
endwith
endscan
endif
endfor
endpro
enddefine
Hopefully anyone could solve my problem here.Thanks!
If i understand correctly, your approach will not work. You don't need to remove columns, you need to add/remove objects to the column and then set the columns current control property to the control you want.
If you want a variety of different controls to display for the same column, then you set the dynamiccurrentcontrol property to an expression that will look at a value and then return the name of the column.control that you want to display dependent upon the logical comparison in the expression.
I think I've ready found the solution, the reason why it unable detect button(control members fo grid) because it is created right after return focus to main form when you have grid created on page frame.
m.result = .t.
frm_.page_.pages(frm_.page_.activepage).btn_print.setfocus() =>to set it focus for later trigger btn_print's gotfocus
=>event,which will be able to change property's of member control of grids.
this.release =>exit "frm" class
Coding for btn_print gotfocus
if m.result=.t.
m.result = .f.
with this.parent.gid_list
.columns(1).btn_qty.enabled = .f.
endwith
endif
Struggle me for one day more until i could find out the reason and solution.
I want to make 3 dependents drop down list, each drop down dependent to the previous drop down, so when I select an item from first drop down , all data fetch from database and add to second drop down as item.
I know how to do this in a normal php page using ajax, but as opencart uses MVC I don't know how can I get the selected value
Basically, you need two things:
(1) Handling list changes
Add an event handler to each list that gets its selected value when it changes (the part that you already know), detailed tutorial here in case someone needed it
Just a suggestion (for code optimization), instead of associating a separate JS function to each list and repeating the code, you can write the function once, pass it the ID of the changing list along with the ID of the depending list and use it anywhere.
Your HTML should look like
<select id="list1" onchange="populateList('list1', 'list2')">
...
</select>
<select id="list2" onchange="populateList('list2', 'list3')">
...
</select>
<select id="list3">
...
</select>
and your JS
function populateList(listID, depListID)
{
// get the value of the changed list thorugh fetching the elment with ID "listID"
var listValue = ...
// get the values to be set in the depending list through AJAX
var depListValues = ...
// populate the depending list (element with ID "depListID")
}
(2) Populating the depending list
Send the value through AJAX to the appropriate PHP function and get the values back to update the depending list (the part you are asking for), AJAX detailed tutorial here
open cart uses the front controller design patter for routing, the URL always looks like: bla bla bla.bla/index.php?route=x/y/z&other parameters, x = folder name that contains a set of class files, y = file name that contains a specific class, z = the function to be called in that class (if omitted, index() will be called)
So the answer for your question is:
(Step 1) Use the following URL in your AJAX request:
index.php?route=common/home/populateList
(Step 2) Open the file <OC_ROOT>/catalog/controller/common/home.php , you will find class ControllerCommonHome, add a new function with the name populateList and add your logic there
(Step 3) To use the database object, I answered that previously here
Note: if you are at the admin side, there is a security token that MUST be present in all links along with the route, use that URL:
index.php?route=common/home/populateList&token=<?php echo $this->session->data['token'] ?> and manipulate the file at the admin folder not the catalog
P.S: Whenever the user changes the selected value in list # i, you should update options in list # i + 1 and reset all the following lists list # i + 2, list # i + 3 ..., so in your case you should always reset the third list when the first list value is changed
P.P.S: A very good guide for OC 1.5.x => here (It can also be used as a reference for OC 2.x with some modifications)
I have got a Kendo Grid and I want to access the data from the row whose detail I expanded. For testing purposes, I have this:
function detailExpand(e)
{
var aux = e.sender.MyModelId;
var aux2 = this.MyModelId;
...
But none of those variables have the MyModelId in it.
I have inspected it and I can't find the model properties unless inside the e.sender._data[index-here] but I don't know the index of the row whose detail I've expanded.
e.sender.dataItem(e.masterRow).MyModelId
http://docs.telerik.com/kendo-ui/api/javascript/ui/grid#events-detailExpand
http://docs.telerik.com/kendo-ui/api/javascript/ui/grid#methods-dataItem
For the record, you should try to avoid using methods starting with an underscore (_). I believe kendo uses the underscore to show it's an internal method (a "private"). Unexpected behavior could occur.
I need to update multiple targets when a link is clicked.
This example builds a list of links.
When the link is clicked, the callback needs to populate two different parts of the .html file.
The actual application uses bokeh for plotting.
The user will click on a link, the 'linkDetails1' and 'linkDetails2' will hold the script and div return from calls to bokeh.component()
The user will click on a link, and the script, div returned from bokeh's component() function will populate the 'linkDetails'.
Obviously this naive approach does not work.
How can I make a list of links that when clicked on will populate two separate places in the .html file?
################################
#views/default/test.html:
{{extend 'layout.html'}}
{{=linkDetails1}}
{{=linkDetails2}}
{{=links}}
################################
# controllers/default.py:
def test():
"""
example action using the internationalization operator T and flash
rendered by views/default/index.html or views/generic.html
if you need a simple wiki simply replace the two lines below with:
return auth.wiki()
"""
d = dict()
links = []
for ii in range(5):
link = A("click on link %d"%ii, callback=URL('linkHandler/%d'%ii), )
links.append(["Item %d"%ii, link])
table = TABLE()
table.append([TR(*rows) for rows in links])
d["links"] = table
d["linkDetails1"] = "linkDetails1"
d["linkDetails2"] = "linkDetails2"
return d
def linkHandler():
import os
d = dict()
# request.url will be linked/N
ii = int(os.path.split(request.url)[1])
# want to put some information into linkDetails, some into linkDiv
# this does not work:
d = dict()
d["linkDetails1"] = "linkHandler %d"%ii
d["linkDetails2"] = "linkHandler %d"%ii
return d
I must admit that I'm not 100% clear on what you're trying to do here, but if you need to update e.g. 2 div elements in your page in response to a single click, there are a couple of ways to accomplish that.
The easiest, and arguably most web2py-ish way is to contain your targets in an outer div that's a target for the update.
Another alternative, which is very powerful is to use something like Taconite [1], which you can use to update multiple parts of the DOM in a single response.
[1] http://www.malsup.com/jquery/taconite/
In this case, it doesn't look like you need the Ajax call to return content to two separate parts of the DOM. Instead, both elements returned (the script and the div elements) can simply be placed inside a single parent div.
# views/default/test.html:
{{extend 'layout.html'}}
<div id="link_details">
{{=linkDetails1}}
{{=linkDetails2}}
</div>
{{=links}}
# controllers/default.py
def test():
...
for ii in range(5):
link = A("click on link %d" % ii,
callback=URL('default', 'linkHandler', args=ii),
target="link_details")
...
If you provide a "target" argument to A(), the result of the Ajax call will go into the DOM element with that ID.
def linkHandler():
...
content = CAT(SCRIPT(...), DIV(...))
return content
In linkHandler, instead of returning a dictionary (which requires a view in order to generate HTML), you can simply return a web2py HTML helper, which will automatically be serialized to HTML and then inserted into the target div. The CAT() helper simply concatenates other elements (in this case, your script and associated div).
I have declared variable in beforeFactory of BIRT Report.
For example:
This variable I am incrementing in table row render like:
Now when all the rows are rendered I want to set above variable to specific cell/ element. I tried
document.getElementName("numberOfMobilityFilesProcessed").text = numberOfMobilityFiles;
AND
reportContext.getDesignHandle().getElementByID
but they are not working out for me.
I had some problems with temporaly local variables used at multiple steps of datasource scripting so I always used global persisting.
After changing your variable you convert it to a String (because only Strings can be persisted) and before editing your variable again, you load the String from persisted context and convert it to the type you want (String to Integer are automatically converted by JavaScripts dynamic typed variables, but don't forget the toString() when you are saving otherwise you will risk an error).
Because you are using reportContext.setPersistentGlobalVariable your variable is accessable in every Element of your Report.
Example:
var rowNum = reportContext.getPersistentGlobalVariable("row_number");
if(rowNum == null){
rowNum = -1;
}
rowNum++;
reportContext.setPersistentGlobalVariable("row_number", rowNum.toString());
Ok, you have a text element displaying a number of row in a table element. The text element appears before the table in the report.
If you are using two separate tasks RunTask and RenderTask:
Add a report variable in your report (see "variable" node on the Data Explorer view). Then you can change the report variable in onCreate() event handler of the table row:
vars["numberOfSomething"] = vars["numberOfSomething"] + 1;
and access its value in an onRender() evenet handler of some text element, for instance DynamicText:
this.text = "Number of something: " + vars["numberOfSomething"];
If you are using RunAndRenderTask, you must look for another approach. In this case an order of onCreate() and onRender() calls is different. You could bind the same DataSet to the text element displaying the counter, as the one bound to the table. Than you can add an aggregation binding to the text element that will count all rows in the dataset.