Вопрос

Here's another one that's got me ripping what's left of my hair out.

My latest asp.net page is something I just threw together for an in-house database tool. It uses the standard VS 2010 design template, which means it uses the site.master page. I mention this because it may be relevant to my problem.

I'm using asp:textbox controls instead of input type="text". When one textbox 'blurs,' I need to run a sub in code-behind that will do a database lookup based on the information typed in the textbox.

Everything I see about this is that I need to add a asp:hiddenfield to trigger the code-behind event to do the lookup. So I use document.GetElementById method in a JavaScript script to set the value in the hidden field. What it's supposed to do is: document.GetElementById('HiddenInfo').value = "yada-yada".

My problem is that the VS development environment doesn't recognize the .value property for GetElelmentById command. For example, as is its wont, VS will give code hints as you type. When I get to where I want to insert the .value parameter, it doesn't show up on the list of suggestions. See illustration:

enter image description here

As you can see, typing the v doesn't bring up the .value parameter.

I've tried getting it by ClientID and by using jquery, and nothing works. The crazy thing is that I have done this before with anther web page I developed, but the only difference is that one did not have a site.master page.

I've spent hours trying to find the answer online, and nothing is quite exactly the same as my problem.

Any ideas?

Thanks!

Это было полезно?

Решение 2

Hours and hours later, I finally found the answer. In the JavaScript function that changes the value of the HiddenInfo field, one line is added that (I guess) forces a postback, which then fires the _ValueChanged event in code behind:

<script language="javascript" type="text/javascript">
function CheckCC() {
    document.getElementById('HiddenInfo').value="YES";
    <%= ClientScript.GetPostBackEventReference(HiddenInfo, "") %>;
}

I dug up the answer here.

Seems like a pretty obscure solution.

The odd thing is that in a previous asp.net design of mine, this wasn't necessary. That's what was really confusing me, and I still don't understand it. But at least I can move forward now.

Thanks everyone for your suggestions.

Другие советы

Well that's an asp .net element, so your going to have to get its clientid I believe. Here it is in jquery:

$('#<%=HiddenInfo.ClientID %>').val();
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top