|
Yes, web services work to a common interface.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Is it possible to check the value of a user control, used on a website by means of a client script on that website. I think it should be of cource, but the 'element.value' notation doesn't work. My user control contains a listbox, initialized in the user control's code. What I'm doing wrong?
Wilfried
|
|
|
|
|
View the source of the page, and you will see that the id of the element is not just "element", but the name of other controls has been prepended to the name.
Use the ClientID property to get the full id that you can use in client code.
I recommend that you use the document.getElementById method instead of just referring to the elements as if they were global variables. It works in most browser in most of the cases, but not always.
A common shorthand for the getElementById is the $ function:
function $(id) { return document.getElementById(id); }
---
single minded; short sighted; long gone;
|
|
|
|
|
Thanks for answering.
Sorry probably my description was not precise. I used the normal access methods already. My user control has the ID sodatum, so I try to access it by:
sodatum.value or
document.getElementById("sodatum").value
but it both returns null. There is another textbox on the same page, named 'artnr' and even another listbox too, both of them accessible.
It must be, because it's a user control. It's implemented in the following way:
<%@ Register TagPrefix="ucSod" TagName="sodat" Src="~/uc/sodatum.ascx" %>
<%@ Page Language="VB" CodeFile="Suche.aspx.vb" Inherits="Suche" %>
<script type ="text/ecmascript">
alert(document.getElementById("artnr").value;
alert(document.getElementById("sodatum").value;
</script>
<form id="frmSuchen" runat="server" method="post">
|asp:TextBox ID="artnr" runat="server" </asp:TextBox>
|ucSod:sodat ID="sodatum" runat="server"/>
</form>
I used '|' instead of '<' here, because otherwise it's not properly displayed in this forum message. In the code there are '<' of course.
The first alert works, the second doesn't.
Wilfried
|
|
|
|
|
wilf57 wrote: The first alert works, the second doesn't.
No, neither of them works. The first alert shows the value of the 'artnr' textbox in the page, not the 'artnr' textbox in the user control.
---
single minded; short sighted; long gone;
|
|
|
|
|
So I found the sh*t myself
asp.net renders a user control differnt than a normal control. The ID of a user control on the webpage is a combination of the ID used on the page and that in the user control HTML code.
Best way: look at the source code of the page created by asp.net and wich ID asp.net used to address the specific control.
Ex.
If the user control is implemented the following way:
|ucSod:sodat ID="sodatum" runat="server"/>
client script access is thru: formxxx.sodatum_sodat.value
(there's a '<' instead of the '|', but then it's not displayed in the forum, why???
-- modified at 9:36 Monday 26th February, 2007
|
|
|
|
|
wilf57 wrote: So I found the sh*t myself
asp.net renders a user control differnt than a normal control. The ID of a user control on the webpage is a combination of the ID used on the page and that in the user control HTML code.
I told you so. Didn't you read my post before you replied to it?
Best way: look at the source code of the page created by asp.net and wich ID asp.net used to address the specific control.
No, the best way is to use the ClientID property, just as I wrote in my previous post. The way that the id is created may change with the version of framework, but the ClientID property will always return the correct id.
---
single minded; short sighted; long gone;
|
|
|
|
|
the last one is an argument, but still:
if there is a user control on the page like this:
<ucSod:sodat ID="sodatum" runat="server"/>
then
document.getElementById("sodatum").value
doesn't work
what works is:
document.getElementById("sodatum_sodat").value
try it (I'm using ie6)
for me it seems logical, because if the control's ID in the server produced HTML code is 'sodatum_sodat' any javascript cannot access the control by 'sodatum'
|
|
|
|
|
You are completely missing the point.
Use the ClientID property to get the name to use in the client code.
If you hard code the name, your code only works with the exact structure that your page has. If anything changes in that structure, the name changes. Also, you can only use the code for that single page, you can't put the user control in another page if it doesn't have the exact same structure.
Also, if you deply the application to a web server, it's not certain that it will use the same pattern to create the name. An update of IIS or the framework may also change the way that the name is constructed.
---
single minded; short sighted; long gone;
|
|
|
|
|
Ok I got that. I read about it in the help too.
<form id="frmSuchen" runat="server" method="post">
<asp:TextBox ID="artnr" runat="server"></asp:TextBox>
<ucSod:sodat ID="sodatum" runat="server"/>
</form>
Now I tried this in the client script:
document.getElementById("<%=artnr.ClientID%>").value
document.getElementById("<%=sodatum.ClientID%>").value
the first statement with the textbox works fine, the second one with the user control doesn't it says:
document.getElementById("<%=sodatum.ClientID%>")is not an object.
and indeed when I execute on the server side (in page_load() or even aftzer loading in a button event:
Msgbox me.sodatum.ClientID
it always prints 'sodatum' and not 'sodatum_sodat' as I'd have expected.
any explainations?
Thanks for your patience
Wilfried
|
|
|
|
|
Is the client script inside the user control? Otherwise you can not reference the controls in that way, you have to specify that they are in the user control. You also have to change their accessibility to public, or expose them through public properties in the user control.
Are you sure that the first one works correctly? Do you get the value from the field in the user control and not the field in the page?
---
single minded; short sighted; long gone;
|
|
|
|
|
The first one is simply a textbox on the page. Thats why it works fine.
The client script is on the page, not in the user control.
I wrote a public property (Text) in the user control, so I can read and write the listbox(the one in the user control) on the server side but that doesn't help on the page client side, right?!
So you say in the page client script I cannot access the listbox inside the user control by its ClientID property , only by the hard coded ID.
Ok next week I'm going skiing, I have do deal with that thing after that.
Thanks again
Wilfried
|
|
|
|
|
wilf57 wrote: I wrote a public property (Text) in the user control, so I can read and write the listbox(the one in the user control) on the server side but that doesn't help on the page client side, right?!
The property is not for use on the client side, but on the server side.
wilf57 wrote: So you say in the page client script I cannot access the listbox inside the user control by its ClientID property , only by the hard coded ID.
You can never access a control from the client side, regardless of where it is. The control only exists on the server side, the only thing that is left of it on the client side is the html elements that it renders.
The concept of a user control doesn't exist on the client side. You can access any element in the page, regardless of how the code for it is created on the server.
What you have to do is simply get access to the right control so that you can get the ClientID for it, then you can use that in the client code to access the control without problem.
---
single minded; short sighted; long gone;
|
|
|
|
|
Hi All
I want to link the data result set from the database, to a DataGrid. I want to display it other than just columns as it comes from the database.
ie. The usual DataGrid format
------------------------------------------------------
Column Data | Column Data | Column Data | Column Data
------------------------------------------------------
I want to display like this:
-------------------------------
Column Data |
-------------|
Column Data | Column Data
-------------|
Column Data |
-------------------------------
Hope that makes sense.
Thanks in advance.
|
|
|
|
|
You can do that,
use Template Field columns in grid view and arrange the column data as needed.
but you can bind the controls using server tags not by data field property.
like Text='<%#DataBinder.Eval(DataBinder.GetDataItem(Container),"Key")%>'
<asp:GridView runat="server" ID="CustomGridView">
<Columns>
<asp:TemplateField>
place you controls as needed here...
</asp:TemplateField>
</Columns>
</asp:GridView>
Cheers
asithangae
|
|
|
|
|
|
Use repeater web server control.
Regards,
Mark
|
|
|
|
|
i want to have textboxes in a panel dynamically for each selected item in listbox to enter the corresponding value..what sould i do?
|
|
|
|
|
There are basically two ways of showing controls dynamically:
:: Put all the controls that you need on the page, and use the Visible property do decide which controls are rendered to the final page.
:: Create controls in code behind and add to the page.
As you already know all the possible combinations of controls that you need, I suggest the first method.
---
single minded; short sighted; long gone;
|
|
|
|
|
Hi
To create controls in the pannel : set the parent property of the control to the pannell that you have created; eg
TextBox txtNew = new TextBox();
panel1.Contains(txtNew);
txtNew.Parent=panel1;
hope this is helpful
|
|
|
|
|
no,it's not working
parent property is readonly
|
|
|
|
|
Try the below code....
Dim txt as New TextBox
Panel1.Controls.Add(txt)
|
|
|
|
|
hi
i could set pranent property in windows application, failed in asp.net sorry did not check out ealier, right method panel1.controls.add
|
|
|
|
|
hi all,
I am working on a page where i have a grid to show the data from the table.I want this grid to be refreshed every 5 mins as the data in table updates every 5 mins.
how it is possible to refresh the grid..
plz give ur suggestions on this.
Thanks in Advance,
cheers
sangeet
|
|
|
|
|
Write this tag in your aspx page ( Source View ) after title tag --
where conten is time interval in seconds. This will refresh the complete page. If you want to avoid complete post back, try to use AJAX instead.
Hope this helps.
"A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder
coolestCoder
|
|
|
|