Link to home
Start Free TrialLog in
Avatar of young_nacs
young_nacs

asked on

How to communicate between javascript and code behind to share value of client control in asp.net and ajax?

I designd A.aspx, A.ascx and A.customControl.js. in order to distinguish the mode of function call B(filepath), I have to save mode in client page as hidden input field by javascript first and call B(filepath). (B() is a SDK of 3rd party which I don't have control of this.) in code behind page, I like to retrieve mode value from client page (browser) to decide mode. How can I do that? here is the sample code on each page. I am also using ajax from javascript.
[A.aspx]
<input type="image"  src="i22a.gif" name="Draft1" value="Draft1" id="_Draft1" onclick="callB(this, '0'); return false;" >
<input type="image"  src="i44a.gif" name="Draft2" value="Draft2" id="_Draft2" onclick="callB(this, '1'); return false;" >
[A.ascx]
<input id="Commandcache" type="hidden" runat="server" size="21" />
[A.customControl.js]
function callB(s,t){
    var x = document.getElementById('Commandcache');
    x.value = t;
    CreateB(s); //Ajax remote function to call server side function
}
[A.ascx.cs]
public bool CreateB(string s)
{
     string cache = this.Commandcache.Value; //error: always return null or empty value
// I don't know this value is always empty even thought I set the value from javascript before call this function.
}

Question: how to send update value when I post new command execute from client to server when I use Ajax feature for partial upate of the page?

Thanks
ASKER CERTIFIED SOLUTION
Avatar of David H.H.Lee
David H.H.Lee
Flag of Malaysia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of young_nacs
young_nacs

ASKER

it means that javascript can call public method in code behind directly?
Dear young_nacs,
Yes, it depend what u want to solve there. You can refer the tutorial from here: http://ajax.schwarz-interactive.de/csharpsample/default.aspx. Let me know if you need any further assistance.