Function from aspx

  • Thread starter Thread starter SimonZ
  • Start date Start date
S

SimonZ

How can you call function from aspx page?

For example:

button on aspx page:
<asp:button Visible="<% =funcVisible()%>" id="btnNew"
Runat="server"></asp:button>


code behind function:

Public Function funcVisible() As Boolean
funcVisible = False
End Function

This won't work.

Regards,S
 
I presume your an asp man and not aspx. In aspx you would do it by assigning
an event to the button or do this

<asp:button onclick=doClick id="btnNew" Runat="server"></asp:button>

and in your code behind file

public void doClick()
{
//do something
}

I would set the visible setting in the codebehind file too. It is much
better to separate the code from the design which is the greatest part of
the .net era.

so in your page load do btnNew.Visible = false;

Hope that helps
 
Hi, Dan

I know I can set everything in code behind.

But I would like to know if it's possible to set the visible property of
some button to call the function from aspx page.

If my button is in some data component(dataGrid for example) it would work
by adding hash sign:

visible="<%# funcVisible()%>"

but if I remove # sign (button is not in data component) it won't work.

Regards,S
 
Hi Simon,

Can i ask why you would ever want to call a function by using a property? (i
dont think it is possible but i have never tried) . There is probably a
better solution to your problem than this method?

Let me know
 
Hi, Dan

it's just curiosity, it's possible to do other way.

What about this example:

I have dataGrid with ItemTemplate and editItem template.

For some users I would like that they see editItem template and change
values, for other users I would like that edit item template is the same as
item template for some items.

Can you do that in code behind, something like:

If user<>"admin" then
datagrid.Item1.editItemTemplate=ItemTemplate
datagrid.Item3.editItemTemplate=ItemTemplate
end if

Any idea?

Regards,
S
 
Sounds like a fair enough method.

--
Dan
SimonZ said:
Hi, Dan

it's just curiosity, it's possible to do other way.

What about this example:

I have dataGrid with ItemTemplate and editItem template.

For some users I would like that they see editItem template and change
values, for other users I would like that edit item template is the same
as item template for some items.

Can you do that in code behind, something like:

If user<>"admin" then
datagrid.Item1.editItemTemplate=ItemTemplate
datagrid.Item3.editItemTemplate=ItemTemplate
end if

Any idea?

Regards,
S
 
I know people jump the example sometimes, not the concept.

I do this, and legimately I feel.

I store my userid's and guids. UserUUID in my example.
HTML doesn't like the hyphens' in the Guid's, when setting the id's of
the aspx controls.

So I strip them out.

My code is in a Repeater, (thus the Eval), but you should be able to
strip it out.


<div id='d<%# GuidSafeName(Convert.ToString(Eval("UserUUID"))) %>'>

</div>




code behind
public string GuidSafeName(string uuid)
{
return uuid.Replace("-", "");
}


Also.
Play with the double and single quotes. Sometimes that'll kill you.

See how in my aspx code, the id for div .. is in a single quote.

...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top