Thursday, March 29, 2012
Set Code Behind Property from Javascript / link?
On my form I want to put a link (html, not asp) who's target is a javascript in my <head> section.
Then I want this Javascript to set the value of my Language property, and in the Set accessor for the property, do some stuff.
Is it possible to set the property in the code behind from your page? Maybe i should just use an asp label running on the server, but I'm trying to see how far i can stay away from anything causing a postback.The Language property exists in the codebehind. You do realize that at some point, you will have to have a postback so that the property can be assigned that value and perform whatever actions it wants to perform. Get it?
You will eventually have to use some sort of a server-side control for this. Here's what I would suggest.
Add a hidden field to your page. When the user clicks on the hyperlink, the javascript function assigns a value to that hidden field. When the page posts back, in the page load event, assign the value of the hidden field to your property. Then let the property do whatever with it.
No, you cannot avoid the postback as far as you've described your setup.
Actually I was stupid anyhow. When hte language change, I got to reload the form with the different language.
I never use hidden fields though. Nevermind
Thanks for reply M.
No prob.
Just been thinking.
What if one do want to set a code behind property from the page?
What if you do want to call a code behind fucntion from a javascript, sitting in hte head section, called by for instance a link clicked?
The answer to your first question is above ^^
The answer to your second question is a little complex. You will need to use javascript to force a postback. You can do this in one of two ways. For example, if you want to call a button's click event, you can call it like
document.getElementById('buttonid').click();
The second way to do this is quite generic. You can use javascript to force a postback.
http://weblogs.asp.net/mnolton/archive/2003/06/04/8260.aspx
Saturday, March 24, 2012
Set focus on a text box
I have developed a aspx web page with c# as page language. I have place two
text boxes and two requiredfield validator control for each text box. Now
whenever i a text box is null, i want to set the focus on the text box apart
from displaying the error message. Please help.
Regards,
SwamiOne way is to handle the onBlur event of the text box:
<asp:TextBox runat="server" id="txt" onblur="if (this.value.replace(/\s/g,
'').length == 0) this.focus();">
"Swami" <Swami@.discussions.microsoft.com> wrote in message
news:CEB6C427-6924-4D9F-B731-7E560DB05FEC@.microsoft.com...
Dear All,
I have developed a aspx web page with c# as page language. I have place two
text boxes and two requiredfield validator control for each text box. Now
whenever i a text box is null, i want to set the focus on the text box apart
from displaying the error message. Please help.
Regards,
Swami
The easiest, most reliable way is client side java script:
MyControl.focus();
Here's more info:
http://wp.netscape.com/eng/mozilla/...f_f-g.htm#59872
You might also consider using this free control:
http://www.metabuilders.com/Tools/FirstFocus.aspx
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
Hire top-notch developers at http://www.able-consulting.com
"Swami" <Swami@.discussions.microsoft.com> wrote in message
news:CEB6C427-6924-4D9F-B731-7E560DB05FEC@.microsoft.com...
> Dear All,
> I have developed a aspx web page with c# as page language. I have place
> two
> text boxes and two requiredfield validator control for each text box. Now
> whenever i a text box is null, i want to set the focus on the text box
> apart
> from displaying the error message. Please help.
> Regards,
> Swami
Check out this code snippet,
http://www.extremeexperts.com/Net/C...ck.
aspx
Saravana
http://dotnetjunkies.com/WebLog/saravana/
www.ExtremeExperts.com
"Swami" <Swami@.discussions.microsoft.com> wrote in message
news:CEB6C427-6924-4D9F-B731-7E560DB05FEC@.microsoft.com...
> Dear All,
> I have developed a aspx web page with c# as page language. I have place
two
> text boxes and two requiredfield validator control for each text box. Now
> whenever i a text box is null, i want to set the focus on the text box
apart
> from displaying the error message. Please help.
> Regards,
> Swami
Set focus on a text box
I have developed a aspx web page with c# as page language. I have place two
text boxes and two requiredfield validator control for each text box. Now
whenever i a text box is null, i want to set the focus on the text box apart
from displaying the error message. Please help.
Regards,
SwamiOne way is to handle the onBlur event of the text box:
<asp:TextBox runat="server" id="txt" onblur="if (this.value.replace(/\s/g,
'').length == 0) this.focus();"
"Swami" <Swami@.discussions.microsoft.com> wrote in message
news:CEB6C427-6924-4D9F-B731-7E560DB05FEC@.microsoft.com...
Dear All,
I have developed a aspx web page with c# as page language. I have place two
text boxes and two requiredfield validator control for each text box. Now
whenever i a text box is null, i want to set the focus on the text box apart
from displaying the error message. Please help.
Regards,
Swami
The easiest, most reliable way is client side javascript:
MyControl.focus();
Here's more info:
http://wp.netscape.com/eng/mozilla/...f_f-g.htm#59872
You might also consider using this free control:
http://www.metabuilders.com/Tools/FirstFocus.aspx
--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
Hire top-notch developers at http://www.able-consulting.com
"Swami" <Swami@.discussions.microsoft.com> wrote in message
news:CEB6C427-6924-4D9F-B731-7E560DB05FEC@.microsoft.com...
> Dear All,
> I have developed a aspx web page with c# as page language. I have place
> two
> text boxes and two requiredfield validator control for each text box. Now
> whenever i a text box is null, i want to set the focus on the text box
> apart
> from displaying the error message. Please help.
> Regards,
> Swami
Check out this code snippet,
http://www.extremeexperts.com/Net/C...erPostback.aspx
--
Saravana
http://dotnetjunkies.com/WebLog/saravana/
www.ExtremeExperts.com
"Swami" <Swami@.discussions.microsoft.com> wrote in message
news:CEB6C427-6924-4D9F-B731-7E560DB05FEC@.microsoft.com...
> Dear All,
> I have developed a aspx web page with c# as page language. I have place
two
> text boxes and two requiredfield validator control for each text box. Now
> whenever i a text box is null, i want to set the focus on the text box
apart
> from displaying the error message. Please help.
> Regards,
> Swami
Tuesday, March 13, 2012
Set pages encoding in code
I will show the page in the language the user selected (English or Japanes).
I do not want to create a seperate page for each language.
On the forms is some UserControls, with say menu's which i build in C# code, and I set the text of menu items according to the selected language.
The body of the page will be text extracted from the database in either English or Japanese.
Can one (should one?) set the page encoding in your code? I've seen that on the older asp pages, the developer set it to one value (en-jpn or sth like that...don't have access to the code as i'm typing), even though the page can be displayed in different languages, what l but sometimes a user have to go and manually set the encoding in his browser for the text to display correctly. (note : *Sometimes*)
Any suggestions what course to follow here?
It seems that with Chinese characters, on don't have problems, but Japanese is a bummer on it's ownGoogle for ResponseEncoding in ASP.NET.
BUT, I don't think that's the way it was meant to be/work. Shouldn't you be checking the language settings of the browser instead? (Tools > Options > languages)