Hide "+" on single record ( add button )

This public forum is for user-to-user discussions of ASP.NET Maker. Note that this is not support forum.
Post Reply
crash
User
Posts: 148

Hide "+" on single record ( add button )

Post by crash »

I am using this code to hide the "+" button if there is a single record.

It is now hiding the "+" button all the time, even if there is no records.

Can anyone tell me why this is not working, or help with the code? I've tried rec count with null, but that also does not work.
I get no errors.

Thanks

// Page Load event
public void Page_Render() {
//Log("Page Render");
var rec_count = ExecuteScalar("select count(*) from <MyTable>.");
if(rec_count != "1")
{
var addlink = OtherOptions["addedit"].GetItem("add");
addlink.Visible = false;
}
}


MichaelG
User
Posts: 1095

Post by MichaelG »

You may want to cast your variable as integer for checking. For example:

int cnt = (int)ExecuteScalar("...");
if (cnt != 1) {
//...
}

If problem persists, open the project with VS 2022, add a break point in your codes and debug from there.


crash
User
Posts: 148

Post by crash »

Thanks that worked well, changed the cnt to O and the button disappears, however, I need it to count the records on the current page, or it blocks other users from adding.

I need to replace <tablename> with the current page, I've tried CurrentPage.RowCount and CurrentPage ... neither work
Can you help? Thanks

This is my working code, this hides the add button:
int cnt = (int)ExecuteScalar("select count(*) from <tablename>");
if (cnt != 0)
{
var addlink = OtherOptions["addedit"].GetItem("add");
addlink.Visible = false;
}


MichaelG
User
Posts: 1095

Post by MichaelG »

Do you mean you want to prevent adding for certain user or page? You can add your your codes as:

if (CurrentPageID() == "..." && CurrentUserName() == "...") {
//... Codes to hide button
}


crash
User
Posts: 148

Post by crash »

No... those functions work fine thanks....I'm trying to hid the button if there is more than one record on the current page.
So my row count or record count is from the current fields you see, if there is more than one row it should hide the + button or de-activate add.
Thanks


MichaelG
User
Posts: 1095

Post by MichaelG »

You need to get the list of all the records in the current page and build the SQL to get the total record count.


crash
User
Posts: 148

Post by crash »

I don't need to show the count...I just need the calculation to hide the button.

ie A rows count function for the current page if hide "+"

It needs to hide if only one record, currently ASPNetmaker allows any user to add as many records as they like, somehow this should be a standard feature as I imagine most users registering on a system will add only single records linked to their profiles.

If I link it to their ID it allows them to keep adding

Thanks


crash
User
Posts: 148

Post by crash »

Can anyone help me with this code, I need to get the record count of the current page.
In some case I need to hide the plus button if single record is viewable and in other cases if a maximum is shown

Thanks


crash
User
Posts: 148

Post by crash »

I have finally managed to get this code to to hide the add link if there is a single record.. this works on my list page... but not in view page..
How would I get this to work on the view and details view page.. thanks.

here is my code

// Page Load event
public void Page_Render() {
//Log("Page Render");

if (TotalRecords == 1)
{
var addlink = OtherOptions["addedit"].GetItem("add");
addlink.Visible = false;
}


MichaelG
User
Posts: 1095

Post by MichaelG »

You can simply use ListRecordCount() instead of TotalRecords.


crash
User
Posts: 148

Post by crash »

Where would I put this.. when I put it in Page Render I get error add link is not recognized.
Thanks very much


Post Reply