Thursday, March 29, 2012
set control on masterpage
Or can you only place stuff in the contentplace holder.
f.e i want to place a label on the masterpage.
and put info in it from a contentpage created from the masterpage
thanxI don't think so and probably this violates the benefit of master pages.
Hi,
Pirate: This can be useful if you have a label on your page and want to change it to reflect what is in your content and I don't see a problem with this myself but my ears are always open to suggestions...
spoofer: You can do it like this...
In your master page define a property public string setLabel
{
set { this.lblTitle.Text = value; }
get { return this.lblTitle.Text; }
}
Then in your content page at the top of the .aspx<%@. MasterType VirtualPath="~/base.master" %>
and in your content page codebehindthis.Master.setLabel = "This is new label";
I'm just following what's called 'best practice' from MS... :p.I've not seen anyone doing it this way.It could be right but rarely used!
Thanx Fishcake, just what i was looking for!
Example + Demo
here:
http://www.geula.biz/works/sample/asp%20net/addControlFromTheContentToTheMaster.aspx
I'm just following what's called 'best practice' from MS... :p.I've not seen anyone doing it this way.It could be right but rarely used!
Not necessarily 'best', then.
There are certain dependencies that do arise in some applications, because a Master Page cannot necessarily be so static. It's also why Master Pages are actually controls that are injected into a page that 'uses' the master page.
Saturday, March 24, 2012
Set Focus to control
I have a content page (I am using a Master Page) that has a control
"ddlRequestType".
In my code behind, I am using the following to create an image and assign
JavaScript to it that will set the focus to the control "ddlRequestType":
If Trim(Me.ddlRequestType.SelectedItem.Text) = "None Selected" Then
strValidateText &= _
"<tr>" & _
"<td width=200><div align=left>Request Type</div></td>" & _
"<td width=400><div align=left><A HREF=#
ONCLICK=ddlRequestType.focus()>" & _
"<IMG SRC=../../images/art_dbflash_go.jpg BORDER=0 ALT=GoTo>" & _
"</div></td>" & _
"</tr>"
strValidateForm = "Validation Error"
End If
However, when I click on the image, I get the following error:
ddlRequestType is undefined.
Any help with this would be appreciated.
Thanks in advance,
sck10Hi,
Try:
document.getElementById('ddlRequestType').focus(); or
Form1.getElementById('ddlRequestType').focus();
Good luck! Ken.
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
If you sign up under me and need help, email me.
"sck10" <sck10@.online.nospam> wrote in message
news:OLLy0hGvEHA.3728@.TK2MSFTNGP12.phx.gbl...
> Hello,
> I have a content page (I am using a Master Page) that has a control
> "ddlRequestType".
> In my code behind, I am using the following to create an image and assign
> JavaScript to it that will set the focus to the control "ddlRequestType":
> If Trim(Me.ddlRequestType.SelectedItem.Text) = "None Selected" Then
> strValidateText &= _
> "<tr>" & _
> "<td width=200><div align=left>Request Type</div></td>" & _
> "<td width=400><div align=left><A HREF=#
> ONCLICK=ddlRequestType.focus()>" & _
> "<IMG SRC=../../images/art_dbflash_go.jpg BORDER=0 ALT=GoTo>" & _
> "</div></td>" & _
> "</tr>"
> strValidateForm = "Validation Error"
> End If
>
> However, when I click on the image, I get the following error:
> ddlRequestType is undefined.
> Any help with this would be appreciated.
> --
> Thanks in advance,
> sck10
>
>
I suggest you to don't use direct id or name for referencing javascript
object, try this:
HREF="java script:document.getElementById('ddlRequestType').focus()"
However i tink is better don't use string for create controls, try add
controls using TableCell,TableRow,ImageButton.
This is a simple example:
Dim tempRow as new TableRow()
Dim tempCell as new TableCell()
Dim myButton as new ImageButton
'Assign properties to rows and cell
myButton.attributes("onclick")="document.getElementById('ddlRequestType').fo
cus()"
tempCell.Controls.Add(myButton )
tempRow.Cells.Add(tempCell)
'add your row to your table rows
"sck10" <sck10@.online.nospam> ha scritto nel messaggio
news:OLLy0hGvEHA.3728@.TK2MSFTNGP12.phx.gbl...
> Hello,
> I have a content page (I am using a Master Page) that has a control
> "ddlRequestType".
> In my code behind, I am using the following to create an image and assign
> JavaScript to it that will set the focus to the control "ddlRequestType":
> If Trim(Me.ddlRequestType.SelectedItem.Text) = "None Selected" Then
> strValidateText &= _
> "<tr>" & _
> "<td width=200><div align=left>Request Type</div></td>" & _
> "<td width=400><div align=left><A HREF=#
> ONCLICK=ddlRequestType.focus()>" & _
> "<IMG SRC=../../images/art_dbflash_go.jpg BORDER=0 ALT=GoTo>" & _
> "</div></td>" & _
> "</tr>"
> strValidateForm = "Validation Error"
> End If
>
> However, when I click on the image, I get the following error:
> ddlRequestType is undefined.
> Any help with this would be appreciated.
> --
> Thanks in advance,
> sck10
>
>
Set Focus to control
I have a content page (I am using a Master Page) that has a control
"ddlRequestType".
In my code behind, I am using the following to create an image and assign
JavaScript to it that will set the focus to the control "ddlRequestType":
If Trim(Me.ddlRequestType.SelectedItem.Text) = "None Selected" Then
strValidateText &= _
"<tr>" & _
"<td width=200><div align=left>Request Type</div></td>" & _
"<td width=400><div align=left><A HREF=#
ONCLICK=ddlRequestType.focus()>" & _
"<IMG SRC=../../images/art_dbflash_go.jpg BORDER=0 ALT=GoTo>" & _
"</div></td>" & _
"</tr>"
strValidateForm = "Validation Error"
End If
However, when I click on the image, I get the following error:
ddlRequestType is undefined.
Any help with this would be appreciated.
--
Thanks in advance,
sck10Hi,
Try:
document.getElementById('ddlRequestType').focus(); or
Form1.getElementById('ddlRequestType').focus();
Good luck! Ken.
--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
If you sign up under me and need help, email me.
"sck10" <sck10@.online.nospam> wrote in message
news:OLLy0hGvEHA.3728@.TK2MSFTNGP12.phx.gbl...
> Hello,
> I have a content page (I am using a Master Page) that has a control
> "ddlRequestType".
> In my code behind, I am using the following to create an image and assign
> JavaScript to it that will set the focus to the control "ddlRequestType":
> If Trim(Me.ddlRequestType.SelectedItem.Text) = "None Selected" Then
> strValidateText &= _
> "<tr>" & _
> "<td width=200><div align=left>Request Type</div></td>" & _
> "<td width=400><div align=left><A HREF=#
> ONCLICK=ddlRequestType.focus()>" & _
> "<IMG SRC=../../images/art_dbflash_go.jpg BORDER=0 ALT=GoTo>" & _
> "</div></td>" & _
> "</tr>"
> strValidateForm = "Validation Error"
> End If
>
> However, when I click on the image, I get the following error:
> ddlRequestType is undefined.
> Any help with this would be appreciated.
> --
> Thanks in advance,
> sck10
I suggest you to don't use direct id or name for referencing javascript
object, try this:
HREF="javascript:document.getElementById('ddlRequestType ').focus()"
However i tink is better don't use string for create controls, try add
controls using TableCell,TableRow,ImageButton.
This is a simple example:
Dim tempRow as new TableRow()
Dim tempCell as new TableCell()
Dim myButton as new ImageButton
'Assign properties to rows and cell
myButton.attributes("onclick")="document.getElementById('ddlRequestType').focus()"
tempCell.Controls.Add(myButton )
tempRow.Cells.Add(tempCell)
'add your row to your table rows
"sck10" <sck10@.online.nospam> ha scritto nel messaggio
news:OLLy0hGvEHA.3728@.TK2MSFTNGP12.phx.gbl...
> Hello,
> I have a content page (I am using a Master Page) that has a control
> "ddlRequestType".
> In my code behind, I am using the following to create an image and assign
> JavaScript to it that will set the focus to the control "ddlRequestType":
> If Trim(Me.ddlRequestType.SelectedItem.Text) = "None Selected" Then
> strValidateText &= _
> "<tr>" & _
> "<td width=200><div align=left>Request Type</div></td>" & _
> "<td width=400><div align=left><A HREF=#
> ONCLICK=ddlRequestType.focus()>" & _
> "<IMG SRC=../../images/art_dbflash_go.jpg BORDER=0 ALT=GoTo>" & _
> "</div></td>" & _
> "</tr>"
> strValidateForm = "Validation Error"
> End If
>
> However, when I click on the image, I get the following error:
> ddlRequestType is undefined.
> Any help with this would be appreciated.
> --
> Thanks in advance,
> sck10
Tuesday, March 13, 2012
Set property in Code-Behind from .aspx page
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.
Set Request.ContentEncoding from code?
I'm having some encoding trouble using my own RequestHandler:
Since the RequestHandler must be able to serve content with diffrent
encoding, I set the Response.Charset and Response.ContentEncoding to the
encoding of current content. Furthermore I set the Content-Type META tag of
the html page to use the same charset as well.
And this all works fine... I get my pages served and both the HTTP headers
and the HTML page has the right encoding applied... Yieppie!!!
But then... when I try to submit a FORM on one of my pages, all my special
characters (like "") gets lost in the process.
The only way I can preserve the special characters, is by setting the
requestEncoding attribute (specified in <globalization> in web.config) to
the same encoding as I the current Response.ContentEncoding. And that is a
bad solution since all of my requests could be in different encodings.
It doesn't work if i try to set the Response.ContentEncoding to the same as
the Request.ContentEncoding. It's as if the Request already has been decoded
using the wrong format (specified in <globalization> in web.config).
Can anyone please help? I'm I on the wrong track? Is it impossible to serve
diffrent request/response encodings through the same web site? Or am I just
doing it the wrong way?
Thanks for your time,
RickyHi Ricky,
From your description, you have met some problem manually setting the
Request's ContentEncoding in ASP.NET via code at runtime, you found it only
works when you specifying them in web.config however what you want it set
different value for each comming request rather than all the same in
web.config , yes?
As for this problem, here are my understanding and suggestions:
The Request/Response 's ContentEncoding set in web.config's Globalization
section is the default setting for the asp.net webapplication. Generally
the comming webrequest is using the encoding from the client(default
setting in browser), if there is no from client, the default setting in
web.config will be used. And also, the Asp.net 's Request and Response
object ContentEncoding can help use manually set them via code. And the
Response's ContentEncoding is nothing particular that we can just set it
before the response content return to client. However, the Request's
ContentEncoding will be a bit different , because when the request comming
, the asp.net runtime will soon checking the ContentEncoding (from client ,
if not, use the default in web.config), So if we set it later in Page's
processing life cycle, it's too late. We must set it before the request is
being processing. In ASP.NET there're several Events during each request's
processing , such as BeginRequest, AuthenticateRequest, EndRequest ...
And the "BeginREquest" is exactly the one we have to use, you can hook this
event in the application 's Global object(Global.asax.cs) or make a custom
HttpModule to handle it. Here are some related reference in MSDN:
#HttpApplication.BeginRequest Event
http://msdn.microsoft.com/library/e...mwebhttpapplica
tionclassbeginrequesttopic.asp?frame=true
#Custom HttpModule Example
http://msdn.microsoft.com/library/e...stomhttpmodules.
asp?frame=true
Also, following is a former thread discussing on a similiar issue, you may
also have a look:
#query string encoding/decoding
http://groups.google.com/groups?hl=...hreadm=PLNLjDdA
EHA.1288%40cpmsftngxa06.phx.gbl&rnum=1&prev=/groups%3Fhl%3Den%26lr%3D%26ie%3
DUTF-8%26oe%3DUTF-8%26q%3Dquerystring%2Bsteven%2Bcheng
Hope helps. Thanks.
Regards,
Steven Cheng
Microsoft Online Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
Thanks for you reply Steven. It works just fine setting the
Request.ContentEncoding in the Application BeginRequest event.
Now my only trouble is how do I select the right encoding for the Request?
Please let me elaborate:
1. I have a RequestHandler that serves content using diffrent encoding. So
when a danish page is being served the "ISO-8859-1" encoding is used by
setting the Response.ContentEncoding property accordingly.
2. The problem occurrs when a user submits form data from a page using
encoding other than the default defined in web.config (usually "utf-8").
Since the request is always beeing decoded using the defaut encoding this
results in characters beeing lost in the process.
3. The solution is to set the Request.ContentEncoding in the Application
BeginRequest event. But how do i know what encoding to use in this context?
Are there any way to tell which encoding the browser used when sending the
request?
Since I have to tell the browser which encoding to use in both the HTTP
Header and the HTML Content-Type Meta tag, the least it could do was to
return the favour and tell me which encoding it used when POSTing data to
me.
Thanks for your time,
Ricky
Hi Ricky,
Thanks for your followup. As for the new question, here are my
understandings:
Generally, all the infos we can ge from the client are all set in the Http
Request 's Header area , the Request object's
UserAgent, Request.ContentType,Request.Browser... etc
We can use the following code to loop through the comming request's header
collection:
foreach(string key in Request.Headers.Keys)
{
Response.Write("<br>"+key+ " : " + Request.Headers[key]);
}
There are some optional items such ad
ACCEPT-LANGUAGE
ACCEPT-ENCODING
ACCEPT-CHARSET
which indicate what kind of language/encoding type / charset the client
browser support. But I've not found anything which directly tell us what
kind of encoding the clieht is using. I think this is determined by the
client machine's OS. And for those new OS such as NT or XP which support
unicode will automatically use the UTF-8 or the certain charset
/contenttype from the serveside when first time getting the page from
server. I think on those old OS such as win98 which doesn't use Unicode may
have different behavior, you may have a test.
Also, you can use the above means to loop the Request's header collection
to see whether there is anyitem which is useful for your determination of
the contentEncoding to change in BeginRequest. If not, I'm afraid we
haven't any means to get anyother clientside's info so far.
Please have a check and if you have any questions, please feel free to post
here. Thanks.
Regards,
Steven Cheng
Microsoft Online Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
Hi Ricky,
Have you had a chance to check out the suggestions in my last reply or have
you got any further ideas on this issue? If you have anything unclear or if
there're anything else we can help, please feel free to post here. Thanks.
Regards,
Steven Cheng
Microsoft Online Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
Hi Steven,
Please forgive me for forgetting to write back with an update on my issue.
I tried looking at the Request object and the informatin found in the
Headers collection, but it provided me with no usefull information when
deciding what encoding should be applied to it.
The most usefull header must be the ACCEPT-CHARSET, but IE never provided me
with this one and Mozilla only returned a list of supported encoding
formats.
I guess this proves that you can't really use multiple encodings on one
ASP.NET application.
Cause as soon as you set the Response Encoding you'll need to decode
subsequent requests as well by applying the right ContentEncoding. And since
this can only be done in the Applications BegingRequest event (before any
process of the request, and creation of session) you'll have no idea what
encoding to use.
I'm still a bit frustrated about it, but for know my solution has been to
duplicate my ASP.NET application to multiple IIS websites and then applied
diffrent encoding to each of these by setting it in the web.config. Anyone
should be able to see that this is a bad solution.
Thanks for your time,
Ricky
Hi Ricky,
Thanks for the followup. Generally all the existing browsers won't send the
content-encoding header in request , some will send the ACCEPT-CHARSET but
which have nothing to do with the actual request or response's content. And
there also nothing on the contentencoding in the W3C's http specification.
So the problem is exising on all the browsers since the browser will
encoded the posted request's content. Here is a certain http1.1 content
encoding reference:
http://i4net.tv/marticle/mod_gzip/encoding.htm
Also, since the UTF-8 is currently the most widely used encoding type which
can represent all the datas from different district. So most browser and
serverside web application use this as the default encoding to process the
request's content. Anyway, I'll consult some further experts to see whether
they have any ideas on this issue and will update you if I got any addition
infos. Thanks.
Steven Cheng
Microsoft Online Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
Hi Ricky,
Regarding on the problem, I'm still consulting and will update you as soon
as possible. Thanks for your understanding.
Regards,
Steven Cheng
Microsoft Online Support
Hi Ricky,
I'm sorry for keeping you waiting for so long time. After further
consulting on some experts, they also confirm that the standard request
dosn't contain such a field which represent the request data's encoding
charset. And we could not get the exactly encoding charset from any header
items but looking at the bytes. And they also suggest that the
ACCEPT- LANGUAGES header is helpful on determining the encoding charset to
use, just check this value in BeginRequest event and set the appropriate
ContentEncoding. Thanks.
Regards,
Steven Cheng
Microsoft Online Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx