473,387 Members | 1,536 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Change in value of custom attribute is not reflecting at server side

Hi All,
I have a web application where I am adding a custom attribute to my ASP.NET
text box control and changing value of that attribute at client side using
JavaScript. My problem is that changed value of that custom attribute is not
reflecting back at server side. Any ideas about this problem?

Server side code:
private void Page_Load(object sender, EventArgs e)
{
if (this.IsPostBack == false)
{
this.txtTarget.Attributes.Add("myCustomAttribute", "Server Side Value");
this.txtTarget.Text = "Server Side Value";
}
else
{
Response.Write("Attribute Value In Page_Load: <b>"
+ this.txtTarget.Attributes["myCustomAttribute"]
+ "</b><br>");
}
}

Client side code:
<script>
function setTextBoxAttribute()
{
var txtTarget = document.getElementById('txtTarget');

alert('Old Attribute Value: ' +
txtTarget.getAttribute('myCustomAttribute'));

txtTarget.setAttribute('myCustomAttribute', 'Client Side Value');
txtTarget.value = 'Client Side Value';
}
</script>

PS: Using input hidden HTML control is not an option for me. I have to use
custom attributes anyhow.
Nov 19 '05 #1
3 3512
Developer:
This simply isn't something that asp.net automatically takes care of. It's
actually quite impossible for ASP.Net to automatically do this. You can
certainly take a look at:
http://www.openmymind.net/FAQ.aspx?documentId=1 which talks about why
dynamically added options to a select don't show up in postback...and you
can apply the same logic to your case.

When a page is posted back, individual attributes aren't posted back...this
is just how HTTP works...ergo ASP.Net can't track changes. I find it
curious how hidden fields aren't an option, since you are relying on
viewstate (which is a hidden field) to do this for you...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"The Developer" <pi*******@gmail.com> wrote in message
news:eE**************@TK2MSFTNGP10.phx.gbl...
Hi All,
I have a web application where I am adding a custom attribute to my ASP.NET text box control and changing value of that attribute at client side using
JavaScript. My problem is that changed value of that custom attribute is not reflecting back at server side. Any ideas about this problem?

Server side code:
private void Page_Load(object sender, EventArgs e)
{
if (this.IsPostBack == false)
{
this.txtTarget.Attributes.Add("myCustomAttribute", "Server Side Value"); this.txtTarget.Text = "Server Side Value";
}
else
{
Response.Write("Attribute Value In Page_Load: <b>"
+ this.txtTarget.Attributes["myCustomAttribute"]
+ "</b><br>");
}
}

Client side code:
<script>
function setTextBoxAttribute()
{
var txtTarget = document.getElementById('txtTarget');

alert('Old Attribute Value: ' +
txtTarget.getAttribute('myCustomAttribute'));

txtTarget.setAttribute('myCustomAttribute', 'Client Side Value');
txtTarget.value = 'Client Side Value';
}
</script>

PS: Using input hidden HTML control is not an option for me. I have to use
custom attributes anyhow.

Nov 19 '05 #2
Thanks for your reply.

In my real application, I'll be having several custom attributes for every
template column in my datagrid. On using hidden field for every of them will
result in increase in size of resulting HTML and in my opinion, using custom
attributes will be the most optimum solution.

I saw an article on codeproject sometime back which uses similar concept in
his VB.NET web application but I am not able to find that article now. So, I
can surely say that this type of behavior is not "impossible" for ASP.NET.
:-)

Any help will be appreciated for this problem.

"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:ex**************@TK2MSFTNGP09.phx.gbl...
Developer:
This simply isn't something that asp.net automatically takes care of. It's actually quite impossible for ASP.Net to automatically do this. You can
certainly take a look at:
http://www.openmymind.net/FAQ.aspx?documentId=1 which talks about why
dynamically added options to a select don't show up in postback...and you
can apply the same logic to your case.

When a page is posted back, individual attributes aren't posted back...this is just how HTTP works...ergo ASP.Net can't track changes. I find it
curious how hidden fields aren't an option, since you are relying on
viewstate (which is a hidden field) to do this for you...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"The Developer" <pi*******@gmail.com> wrote in message
news:eE**************@TK2MSFTNGP10.phx.gbl...
Hi All,
I have a web application where I am adding a custom attribute to my

ASP.NET
text box control and changing value of that attribute at client side using JavaScript. My problem is that changed value of that custom attribute is

not
reflecting back at server side. Any ideas about this problem?

Server side code:
private void Page_Load(object sender, EventArgs e)
{
if (this.IsPostBack == false)
{
this.txtTarget.Attributes.Add("myCustomAttribute", "Server Side

Value");
this.txtTarget.Text = "Server Side Value";
}
else
{
Response.Write("Attribute Value In Page_Load: <b>"
+ this.txtTarget.Attributes["myCustomAttribute"]
+ "</b><br>");
}
}

Client side code:
<script>
function setTextBoxAttribute()
{
var txtTarget = document.getElementById('txtTarget');

alert('Old Attribute Value: ' +
txtTarget.getAttribute('myCustomAttribute'));

txtTarget.setAttribute('myCustomAttribute', 'Client Side Value');
txtTarget.value = 'Client Side Value';
}
</script>

PS: Using input hidden HTML control is not an option for me. I have to use custom attributes anyhow.


Nov 19 '05 #3
you approach will not work.

when the browser does a form submit (postback in .net terms), it posts the
control name and value (name=value) only. it will only postback <input>,
<button>, <select> and <textarea> elements inside the posting form. they
must also be enabled and have a name.
-- bruce (sqlwork.com)

"The Developer" <pi*******@gmail.com> wrote in message
news:eE**************@TK2MSFTNGP10.phx.gbl...
Hi All,
I have a web application where I am adding a custom attribute to my
ASP.NET
text box control and changing value of that attribute at client side using
JavaScript. My problem is that changed value of that custom attribute is
not
reflecting back at server side. Any ideas about this problem?

Server side code:
private void Page_Load(object sender, EventArgs e)
{
if (this.IsPostBack == false)
{
this.txtTarget.Attributes.Add("myCustomAttribute", "Server Side
Value");
this.txtTarget.Text = "Server Side Value";
}
else
{
Response.Write("Attribute Value In Page_Load: <b>"
+ this.txtTarget.Attributes["myCustomAttribute"]
+ "</b><br>");
}
}

Client side code:
<script>
function setTextBoxAttribute()
{
var txtTarget = document.getElementById('txtTarget');

alert('Old Attribute Value: ' +
txtTarget.getAttribute('myCustomAttribute'));

txtTarget.setAttribute('myCustomAttribute', 'Client Side Value');
txtTarget.value = 'Client Side Value';
}
</script>

PS: Using input hidden HTML control is not an option for me. I have to use
custom attributes anyhow.

Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Bart.NET | last post by:
Hi, I want to prefix my attributes in a custom control. So like this: <x:Mycontrol x:id="22" x:name="SomeName" runat="server"/> Now I get a "The server tag is not well formed.". Do you know...
2
by: Linus Martinsson | last post by:
How can I change attribute in html elements from my aspx.cs page? For example if I want to change the src-attribute in an iframe. //Linus
2
by: TJS | last post by:
in a custom control which renders a form, is there a way to define the form action other than the preset postback. I've seen several but they are all an httpModule of sorts. I would like to do...
5
by: | last post by:
I am wondering what the best method of attaching custom Events to custom WebUserControls are. I cannot seem to find the proper terminology to expand my research. Basicallly I have a custom user...
2
by: Alan Silver | last post by:
Hello, I have a custom validator on my page, and have the server-side code working fine. I want to add a client-side funtion as well, but am not sure how to wire it in so that it works with the...
1
by: serge calderara | last post by:
dear all, i am a bit confused on the way custom error are handling and occurs. First of all I have understand that customer error is used to defined more user friendly message to my end user and...
9
by: wardy1975 | last post by:
Hi All, Looking for a little expert advice on a few web standards issues. I am currently trying to understand the impact of web standards for a web application I work with. I have been doing a...
0
by: Zed | last post by:
Hi, I would like to create a custom attribute for my C# application which will decorate methods. So far no problems. But I noticed that the attirbute constructor being called only when I reflecting...
1
by: ppioter | last post by:
hi this regards asp.net 1.1 I have following problem I would like to change attribute of <LINKtag via ASP I have this definition inside <HEADsection of my aspx file <LINK id="stylesheet"...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.