473,887 Members | 2,353 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(objec t sender, EventArgs e)
{
if (this.IsPostBac k == false)
{
this.txtTarget. Attributes.Add( "myCustomAttrib ute", "Server Side Value");
this.txtTarget. Text = "Server Side Value";
}
else
{
Response.Write( "Attribute Value In Page_Load: <b>"
+ this.txtTarget. Attributes["myCustomAttrib ute"]
+ "</b><br>");
}
}

Client side code:
<script>
function setTextBoxAttri bute()
{
var txtTarget = document.getEle mentById('txtTa rget');

alert('Old Attribute Value: ' +
txtTarget.getAt tribute('myCust omAttribute'));

txtTarget.setAt tribute('myCust omAttribute', '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 3541
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*******@gmai l.com> wrote in message
news:eE******** ******@TK2MSFTN GP10.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(objec t sender, EventArgs e)
{
if (this.IsPostBac k == false)
{
this.txtTarget. Attributes.Add( "myCustomAttrib ute", "Server Side Value"); this.txtTarget. Text = "Server Side Value";
}
else
{
Response.Write( "Attribute Value In Page_Load: <b>"
+ this.txtTarget. Attributes["myCustomAttrib ute"]
+ "</b><br>");
}
}

Client side code:
<script>
function setTextBoxAttri bute()
{
var txtTarget = document.getEle mentById('txtTa rget');

alert('Old Attribute Value: ' +
txtTarget.getAt tribute('myCust omAttribute'));

txtTarget.setAt tribute('myCust omAttribute', '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******** ******@TK2MSFTN GP09.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*******@gmai l.com> wrote in message
news:eE******** ******@TK2MSFTN GP10.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(objec t sender, EventArgs e)
{
if (this.IsPostBac k == false)
{
this.txtTarget. Attributes.Add( "myCustomAttrib ute", "Server Side

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

Client side code:
<script>
function setTextBoxAttri bute()
{
var txtTarget = document.getEle mentById('txtTa rget');

alert('Old Attribute Value: ' +
txtTarget.getAt tribute('myCust omAttribute'));

txtTarget.setAt tribute('myCust omAttribute', '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*******@gmai l.com> wrote in message
news:eE******** ******@TK2MSFTN GP10.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(objec t sender, EventArgs e)
{
if (this.IsPostBac k == false)
{
this.txtTarget. Attributes.Add( "myCustomAttrib ute", "Server Side
Value");
this.txtTarget. Text = "Server Side Value";
}
else
{
Response.Write( "Attribute Value In Page_Load: <b>"
+ this.txtTarget. Attributes["myCustomAttrib ute"]
+ "</b><br>");
}
}

Client side code:
<script>
function setTextBoxAttri bute()
{
var txtTarget = document.getEle mentById('txtTa rget');

alert('Old Attribute Value: ' +
txtTarget.getAt tribute('myCust omAttribute'));

txtTarget.setAt tribute('myCust omAttribute', '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
1876
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 any solution?
2
3495
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
2032
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 it at the page or control level if possible. thanks
5
4552
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 control that has 2 or 3 events selectionChanged DropDownOpened I would like the user to be able to attach Server Side events for both. I have the client side implementation worked out. I just need to find a proper way to to get everything...
2
1799
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 other validators on the page. I specified the name of the Javascript function with the ClientValidationFunction attribute of the custom validator, and it is being called fine. However, if the validator returns false (ie bad
1
1517
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 that custom errors mask out more details error if the web side is access from the local web server browser right ? If it is so I have read that setting the mode attribute to OFF in web.config
9
3147
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 lot of research in the areas of XHTML and WAI compliance, and am attempting to come up with a recommendation for our product in terms of standards level compliance. Ideally, I would like to be at XHTML 1.0 Strict. However, in my reading I have...
0
774
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 the attribute parameters. I would like that the attribute's constructor will be called every time I enter the method (like when decorate a class with an attribute and its contructor being called when creating an instance of the class). How can I do...
1
1801
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" href="test1.css" type="text/css" rel="stylesheet" > I want it to be changed to following when user checks different theme from
0
9957
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9799
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10770
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9593
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7141
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5809
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4632
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4238
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3245
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.