get control id from the content page
-
hi, i have need a functionality like as soon we click the button at the moment that button will hide and after that the functionality should fire written in code behind along with that button.i am working as follows;
function check() { document.getElementById('Button1').style.visibility= "hidden"; return false; }
code behind as follows:protected void Page_Load(object sender, EventArgs e) { Button1.Attributes.Add("onclick", "javascript:return check()"); } protected void Button1_Click(object sender, EventArgs e) { Response.Write("success"); }
this not working properly. and i have to do this for a content page having this Button1 so the problem is the the getElementById is not working. Regards, Srinandan.. -
hi, i have need a functionality like as soon we click the button at the moment that button will hide and after that the functionality should fire written in code behind along with that button.i am working as follows;
function check() { document.getElementById('Button1').style.visibility= "hidden"; return false; }
code behind as follows:protected void Page_Load(object sender, EventArgs e) { Button1.Attributes.Add("onclick", "javascript:return check()"); } protected void Button1_Click(object sender, EventArgs e) { Response.Write("success"); }
this not working properly. and i have to do this for a content page having this Button1 so the problem is the the getElementById is not working. Regards, Srinandan..When the HTML is written out to the Page, your button's ID in the HTML probably isn't "Button1". That means your javascript method will fail. To get around this, write the javascript into a String on the Server-Side and add it to the Page by using the RegisterClientScriptBlock method. When inserting the Button's ID, use MyButton.ClientID to get the correct id.
Mark, http://aspnetlibrary.com
-
hi, i have need a functionality like as soon we click the button at the moment that button will hide and after that the functionality should fire written in code behind along with that button.i am working as follows;
function check() { document.getElementById('Button1').style.visibility= "hidden"; return false; }
code behind as follows:protected void Page_Load(object sender, EventArgs e) { Button1.Attributes.Add("onclick", "javascript:return check()"); } protected void Button1_Click(object sender, EventArgs e) { Response.Write("success"); }
this not working properly. and i have to do this for a content page having this Button1 so the problem is the the getElementById is not working. Regards, Srinandan..if you say return false; the page will not submit
Regards, Sylvester G sylvester_g_m@yahoo.com
-
if you say return false; the page will not submit
Regards, Sylvester G sylvester_g_m@yahoo.com
-
thanks for reply if i will make the return true then the button will hide for moment but i have need to hide for that time. srinandan..
when the button again want to visible for you?
Regards, Sylvester G sylvester_g_m@yahoo.com
-
hi, i have need a functionality like as soon we click the button at the moment that button will hide and after that the functionality should fire written in code behind along with that button.i am working as follows;
function check() { document.getElementById('Button1').style.visibility= "hidden"; return false; }
code behind as follows:protected void Page_Load(object sender, EventArgs e) { Button1.Attributes.Add("onclick", "javascript:return check()"); } protected void Button1_Click(object sender, EventArgs e) { Response.Write("success"); }
this not working properly. and i have to do this for a content page having this Button1 so the problem is the the getElementById is not working. Regards, Srinandan..In order to ensure that controls have a unique id on the page, ASP.NET will rename your controls as it renders them. In order for you to retrieve the id of a server control on the client side, you will need to progratically reference the
ClientID
property of the button. Using theClientID
property, you could refactor your code into something like: Client Script:<script language="javascript" type="text/javascript">
function check(buttonId)
{
button = document.getElementById(buttonId);
if (button)
{
button.style.visibility = "hidden";
}
return false;
}
</script>
Server Code:
protected void Page_PreRender(object sender, EventArgs ea)
{
button1.Attributes.Add("onclick", String.Format("javascript:return
-
when the button again want to visible for you?
Regards, Sylvester G sylvester_g_m@yahoo.com
thanks Sylvester As soon the button will click at the moment it should be hide after that the Button1_Click() events should fire. in this method i am check some condition if the functionality goes success then no need to show that button if functionality failure then the button should visible its all. regards, Srinandan
-
In order to ensure that controls have a unique id on the page, ASP.NET will rename your controls as it renders them. In order for you to retrieve the id of a server control on the client side, you will need to progratically reference the
ClientID
property of the button. Using theClientID
property, you could refactor your code into something like: Client Script:<script language="javascript" type="text/javascript">
function check(buttonId)
{
button = document.getElementById(buttonId);
if (button)
{
button.style.visibility = "hidden";
}
return false;
}
</script>
Server Code:
protected void Page_PreRender(object sender, EventArgs ea)
{
button1.Attributes.Add("onclick", String.Format("javascript:return
-
thanks Sylvester As soon the button will click at the moment it should be hide after that the Button1_Click() events should fire. in this method i am check some condition if the functionality goes success then no need to show that button if functionality failure then the button should visible its all. regards, Srinandan
in the catch block you can make the button visible like the following line Button1.Visible = true;
Regards, Sylvester G sylvester_g_m@yahoo.com
-
in the catch block you can make the button visible like the following line Button1.Visible = true;
Regards, Sylvester G sylvester_g_m@yahoo.com
-
thanks you Jesse but problem with here when return false then the server code is not firing i have need to visible=hidden in client and then fire the server code Regards, Srinandan
I'm sorry, I must have misunderstood your post. If you'd like the server code to fire, simply change the javascript function to return
true
instead.--Jesse "... the internet's just a big porn library with some useful articles stuck in." - Rob Rodi
-
I'm sorry, I must have misunderstood your post. If you'd like the server code to fire, simply change the javascript function to return
true
instead.--Jesse "... the internet's just a big porn library with some useful articles stuck in." - Rob Rodi