Showing posts with label created. Show all posts
Showing posts with label created. Show all posts

Saturday, March 31, 2012

Set a default property in a user control?

I'm not even sure if what I'm doing is possible. I created a simple control
that will be reused throughout the site. It will accept a large amount of
HTML with bulleted lists, etc
I want to implement like:
<uc1:KeyFeatures id="KeyFeatures1" runat="server">
Large amount of Inner Html content goes here between tags...
</uc1:KeyFeatures>
Not like:
<uc1:KeyFeatures id="KeyFeatures1" runat="server" InnerHtml="Large amount of
Inner Html content goes here between tags..."></uc1:KeyFeatures>
Can I do it this way? If so, is this considered the 'default' property and h
ow do I declare this in my uc so it accepts the text between the tags?
The code is below..this is a stripped down version.
public class KeyFeatures : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.Label lblInnerHtml;
public string InnerHtml
{
set
{
lblInnerHtml.Text = value;
}
}If you find can you please tell here how you do?
Iyigun
"Dave" <anonymous@.discussions.microsoft.com> wrote in message
news:243F1108-1CB3-4F93-8386-BE39FC3601CA@.microsoft.com...
> I'm not even sure if what I'm doing is possible. I created a simple
control that will be reused throughout the site. It will accept a large
amount of HTML with bulleted lists, etc
> I want to implement like:
> <uc1:KeyFeatures id="KeyFeatures1" runat="server">
> Large amount of Inner Html content goes here between tags...
> </uc1:KeyFeatures>
> Not like:
> <uc1:KeyFeatures id="KeyFeatures1" runat="server" InnerHtml="Large amount
of Inner Html content goes here between tags..."></uc1:KeyFeatures>
> Can I do it this way? If so, is this considered the 'default' property and
how do I declare this in my uc so it accepts the text between the tags?
> The code is below..this is a stripped down version.
> public class KeyFeatures : System.Web.UI.UserControl
> {
> protected System.Web.UI.WebControls.Label lblInnerHtml;
> public string InnerHtml
> {
> set
> {
> lblInnerHtml.Text = value;
> }
> }
>
>
>
>
>

Set a default property in a user control?

I'm not even sure if what I'm doing is possible. I created a simple control that will be reused throughout the site. It will accept a large amount of HTML with bulleted lists, et

I want to implement like

<uc1:KeyFeatures id="KeyFeatures1" runat="server"
Large amount of Inner Html content goes here between tags..
</uc1:KeyFeatures

Not like

<uc1:KeyFeatures id="KeyFeatures1" runat="server" InnerHtml="Large amount of Inner Html content goes here between tags..."></uc1:KeyFeatures

Can I do it this way? If so, is this considered the 'default' property and how do I declare this in my uc so it accepts the text between the tags?

The code is below..this is a stripped down version.

public class KeyFeatures : System.Web.UI.UserContro

protected System.Web.UI.WebControls.Label lblInnerHtml

public string InnerHtml

se

lblInnerHtml.Text = value
If you find can you please tell here how you do?
Iyigun

"Dave" <anonymous@.discussions.microsoft.com> wrote in message
news:243F1108-1CB3-4F93-8386-BE39FC3601CA@.microsoft.com...
> I'm not even sure if what I'm doing is possible. I created a simple
control that will be reused throughout the site. It will accept a large
amount of HTML with bulleted lists, etc
> I want to implement like:
> <uc1:KeyFeatures id="KeyFeatures1" runat="server">
> Large amount of Inner Html content goes here between tags...
> </uc1:KeyFeatures>
> Not like:
> <uc1:KeyFeatures id="KeyFeatures1" runat="server" InnerHtml="Large amount
of Inner Html content goes here between tags..."></uc1:KeyFeatures>
> Can I do it this way? If so, is this considered the 'default' property and
how do I declare this in my uc so it accepts the text between the tags?
> The code is below..this is a stripped down version.
> public class KeyFeatures : System.Web.UI.UserControl
> {
> protected System.Web.UI.WebControls.Label lblInnerHtml;
> public string InnerHtml
> {
> set
> {
> lblInnerHtml.Text = value;
> }
> }
>
>
>

Monday, March 26, 2012

Set Default value for a Property in a user defined class

Hello,
I have created a class in vb .net and would like to add a property tothis class with a default value. The purpose of this would bethat if the user didn't supply a value for the property (or evenreference the property) it would contain the default value. Forexample here is what I have tried:
Public Shared MultipleResults As Boolean = False
My pages don't work properly as the property doesn't seem to be set to False.
Thanks in advance,
Paul Liadis
Penn State University
What do you mean by "pages don't work properly"? Do they crash or are you just not getting the results you expect?
An uninitialized Boolean will return False (which is ambiguous, of course). For example:
Class Test
Public Shared MultipleResults As Boolean = False
Public Shared MultipleResultsUnInit As Boolean
End Class
Sub Button1_Click(sender As Object, e As EventArgs)
Dim t As New Test
Response.Write("<br>Value = " & t.MultipleResults)
Response.Write("<br>Value = " & t.MultipleResultsUnInit)
End Sub

When I run this, I get False for both properties.
Are you perhaps running into the issue that the property value is not being persisted across postbacks?


Sorry about the vague statement "doesn't work". The pages do notcrash. They give results that I did not expect. Here is avery small version of the example you gave, with slight midifications:
Class Test
Public Shared globalCustomColumnWidths As Boolean = False
' many other subroutines and such here
shared sub ASubroutine()
If globalCustomColumnWidths = False Then
TableCellObj.Width = Unit.Percentage(25)
Else
TableCellObj.Width = Unit.Percentage(globalWidthArray(0))
End If
end sub
End Class
What I would like to happen is that when I call my test class, I would like for globalCustomerColumnWidths to
evaluate to false, even if I don't set it to anything. This doesn't seem to be happening. Any thoughts? Also,
what did you mean by "An uninitialized Boolean will return False (which is ambiguous, of course)."?
Thanks for the response.



Sorry, I'm not understanding the relationship between globalCustomColumnWidths and MultipleResults. (?)
>"ambiguous, of course"
That if an uninitialized Boolean returns false, you don't know whether it's uninitialized or has been explicitly set to false.

Thursday, March 22, 2012

Set Focus to User Control

I have created a user control in ASP.Net that embeds a datagrid so as to extend lots of features, the problem is that I cant set focus to the datagrid within the user control on page load. I've tried with some javascript snippets but this would not work, it would give me a javascript error stating that the control name I have used in my focus script is null or does not exists(even though I have used the id generated by .Net i.e: MyUserControlName_UserControlDatagridName). Anybody has an idea how to work around this.

all help appreciated, thanxImportant note:
Your usercontrol doesn't receive focus, because it doesn't render as an htmlcontrol that uniquely identifies it. It only exists on the server side inside the .Net framework. Once it gets to the client, 'it' is only the composition of the html that makes it useful.

Let's pretend that instead of your control, your using this control:

A control class called 'MyTextBox' which inside it contains:
An asp:textbox
An asp:RequiredFieldValidator

You also slap an ID on the asp:textbox of 'textboxAlpha'
And an ID on the RequiredFieldValidtor of 'rq1'

Now, when you throw your MyTextBox control on a webform, ASP.NET will probably give it an ID of 'MyTextBox1', and unless you rename the ID, it will take that by default.

Now... to access the textbox in this control from Javascript you would use:

document.getElementById('MyTextBox1_textboxAlpha');

That's easy enough.

Things get a little different when working with 'databound-controls'.

I know that for repeaters... to get to the contents of a textbox inside the repeater, you have to use 'repeater1_ctrl0_ctrl0'.

The first _ctrl0 part is actually the first listed dataitem, and the second _ctrl0 is the first control in that dataitem.

So for a repeater... if you had two items that were listed, and in the repeater item template you told it to render THREE textboxes with each item that gets listed, your repeater would have these controls:
repeater1_ctrl0_ctrl0
repeater1_ctrl0_ctrl1
repeater1_ctrl0_ctrl2
repeater1_ctrl1_ctrl0
repeater1_ctrl1_ctrl1
repeater1_ctrl1_ctrl2

Anyway, best thing to do is choose View Source after your page has rendered, and look what the DataGrid wrote for you. You'll be looking for an INPUT tag that would have the name of your Datagrid plus _ctrl0 or something like that.
Thanx for the reply but actually I still cant get this to work. As you can see the HTML output of the page is similar to this:

<div id="UcDtgMain_pnlMain" style="border-width:0px;border-style:Solid;Width:0;Height:226;">
<div id="UcDtgMain_pnlHeader" align="Center">
<span id="UcDtgMain_lblTitre" class="TitleStyle">Title of DataGrid</span>
</div>
<table class="DataGridStyle" cellspacing="0" id="UcDtgMain_DataGrid1">
<tr><td>Code</td><td>Description</td></tr>
<tr class="ItemStyle">
<td align="Right"><span id="UcDtgMain_DataGrid1__ctl2_lblCode"><acronym Title='1'>1</acronym></span></td><td align="Left"><span id="UcDtgMain_DataGrid1__ctl2_lblDescription"><acronym Title='Monsieur'>Monsieur</acronym></span></td></tr>
<tr class="AlternatingItemStyle" onclick="javascript:__doPostBack('UcDtgMain:DataGrid1:_ctl3:LinkButton1','')">
<td align="Right"><span id="UcDtgMain_DataGrid1__ctl3_lblCode"><acronym Title='2'>2</acronym></span></td><td align="Left"><span id="UcDtgMain_DataGrid1__ctl3_lblDescription"><acronym Title='Madame'>Madame</acronym></span></td>
</tr><tr class="ItemStyle" onclick="javascript:__doPostBack('UcDtgMain:DataGrid1:_ctl4:LinkButton1','')">
<td align="Right"><span id="UcDtgMain_DataGrid1__ctl4_lblCode"><acronym Title='3'>3</acronym></span></td><td align="Left"><span id="UcDtgMain_DataGrid1__ctl4_lblDescription"><acronym Title='Mademoiselle'>Mademoiselle</acronym></span></td>
</tr><tr class="AlternatingItemStyle" onclick="javascript:__doPostBack('UcDtgMain:DataGrid1:_ctl5:LinkButton1','')">
<td align="Right"><span id="UcDtgMain_DataGrid1__ctl5_lblCode"><acronym Title='4'>4</acronym></span></td><td align="Left"><span id="UcDtgMain_DataGrid1__ctl5_lblDescription"><acronym Title='Sir'>Sir</acronym></span></td>
</tr><tr class="ItemStyle" onclick="javascript:__doPostBack('UcDtgMain:DataGrid1:_ctl6:LinkButton1','')">
<td align="Right"><span id="UcDtgMain_DataGrid1__ctl6_lblCode"><acronym Title='5'>5</acronym></span></td><td align="Left"><span id="UcDtgMain_DataGrid1__ctl6_lblDescription"><acronym Title='Miss'>Miss</acronym></span></td>
</tr>
</table>

</div>

So basically there are a set on container controls that have been created and even if I use this:

Page.RegisterStartupScript("focus", _
"<script language=""JavaScript"">" & vbCrLf & vbTab & _
"document.getElementById(""UcDtgMain_DataGrid1__ctl2_lblCodeLIBCIVILITE"").focus();" & vbCrLf & _
"<" & "/script>")

it simply does not seem to work, am I missing something over here? I Think that maybe since the controls are finally interpreted as HTML tables then this might be the reason for this.
Well, spans can't receive focus. You have to have at least some control that can (usually ony type="INPUT" ), in your Item and AlternatingItem templates. Additionally, I'm pretty sure TR's cant receive events period, they must be TD's for onclicks... I could be wrong on that last part though.

Anyway, concerning the first part, I've seen people put a checkbox to select, which postsback and changes the TD (TD with a table and then a TR, and then TD's for each control in that datarow) background-color to mark it as selected, or simply throw a linkbutton that does nothing but simply display the Text in the span.
In fact, setting the datagrid's selected index to 1 would make the first row being selected and it would change in color, thus appearing to be selected. But since I use the arrow keys to navigate through the grid, it does not scroll up and down the grid until I perform a first click on the control. So maybe there is another work around for this.
Actually my datagrid user control is quite heavy in terms of functionalities, it even allows navigating through the control through arrow keys, allows paging to be done on Page Up and Page Down keys, column sorting and lots of other useful stuffs.
Anyway, I dont know if others have developed a similar control but it would have been good if they did. Maybe some of us could work on a more enhanced version of the datagrid control!!! Anybody wanna go for it? :rolleyes:

thanx again.

set image url programmatically for image control

I have a print page that uses an image control to display an image that is saved in a directory that is dynamically created upon a session start. I have the path readily available for the image control...but I am failing to get the image to display in the image control...

what is the syntax to properly set the url for an image control programmatically in the code behind?

the control is named printImage

thanks in advance

Eric

printImage.src=


printImage.ImageUrl = "your URL";

simple as that.


I am not getting the .src in intellisense for the control - is there a namespace/directive that I am missing?


ekeefauver:

I am not getting the .src in intellisense for the control - is there a namespace/directive that I am missing?

Nope, it's just, that property is called "ImageUrl" and not "src".


doesn't seem to work for me...do I somehow need to refresh the control after setting the URL to the image?

the path to the image is: C:\Documents and Settings\dekeefau\My Documents\Visual Studio 2005\WebSites\CMAT_FINAL\sessions\sd_ewwewtjwy23b5vnrmxm1mffz\print\theimage.bmp

which is stored in a string variable


No, there is no need to refresh the control. Perhaps the path you are using is not valid? Try using Server.MapPath() function with the relative path to the image in question.

Example:

Image is in the /Images subfolder of the application and its name is MyImage.gif

Then the code to display this image would be:

printImage.ImageUrl = Server.MapPath("~/Images/MyImage.gif");

Tuesday, March 13, 2012

Set property in Code-Behind from .aspx page

Hello there,

I have a number of aspx pages that are all the same but with different data in them. These pages are created by a content management system, and also retrieve some Database content based on a unique SQL statement.
Here are two .asp example pages so you can see what I am getting at:
http://www.cntraveller.co.uk/guides/England/
http://www.cntraveller.co.uk/guides/USA/

There is going to be one .dll file for all of these pages but I need to alter the SQL statment depending on which page you are viewing, for example for the Engand page it would be something like:
"SELECT * from Counties where Country = 'GB'" and the USA;
"SELECT * from Counties where Country = 'USA'".

My problem is I want to set somewhere in the .aspx page a variable that can be used in the SELECT statment. I have tried defining a function in the .aspx page like:


<script language="C#" runat="server">
void SetLBCountry()
{
this.strLBCountry = "GB";
}
</script>

and calling it from my .dll like this:


public strLBCountry;
private void Page_Load(object sender, System.EventArgs e)
{
SetLBCountry();
}

but it does not recognise the function when I compile it.

Anyone have any idea as to what I can do?

Thanks in advance,
Dave Asbury.You're going the wrong way, essentially you want the base class (codebehind) to call a sub only defined in a derived class (aspx page). It doesn't work that way. Why can't you just do this from the codebehind class?
Can you not simply parse the Request.Url to see what contry they are viewing from and then use some sort of select statement to get the relevant query string.. This could all be done in teh Page_Load method of the .dll
Thanks for your reply,

This is a good idea, but editors can create new folders and pages using the content management system and I don't want to have to edit the .dll to add in a new "If Request.Url = "blah blah" then strSQL = "SELECT BLAH" type statement.

I can see that there probably going to be other situations that require a similar solution too that I haven't come accross yet.

What I really would like is to be able to set a number of parameters in the .aspx page (this is the page that is created in the content management system from a template) that can be passed into the .dll - just like a form element or a querystring BUT that is set in the page the first time you view it (if you see what I mean!).

Any ideas??
Thanks for your reply,

I need to do it this way as I have my codebehind base class all set up and running fine, but I need all the different countries to use this one .dll but they all need different SQL statements.

The .aspx files are created by editorial staff using a content management system that uses a template and merges this with the data they put in to create the .aspx file.

What I want is for one of the fields they enter to be the key that is used to retreive further data from the database at run time - exactly as if I passed in a querystring or a form element - BUT I want this parameter to be in the page all the time so that when the page is viewed it is picked up and used inside the .dll file.

Do you see what I mean?
Still not sure if I get you fully, but could you an asp:textbox control to the page, you could set its text field to the value that you want and then set it Visiblity to false so that it doesn't show up on the page? you could then get the value of the textbox in the code behind page.
Yes!

That is exactly what I want, now you point it out I feel stupid for not seeing it.
Thanks for the help and sorry for taking up your time.

Dave.