hello,
i have one linkbutton when i click on linkbutton i insert record in DB using onclick=Linkbutton_click. if successfully insert then returnvalue is 1. after return 1 i want to call javascript function. how i can do this? Reply ASAP. Is It Possible?
e.g.
<asp:LinkButton ID="Operation_Link" runat="server" OnClick="Operation_Link_Click">asp:LinkButton>
protected void Operation_Link_Click(object sender, EventArgs e){
if (Operation_Link.Text == "SUBMIT"){
ReturnValue = company.InsertCompany(CompanyNm_TXT.Text, int.Parse(City_List.SelectedValue), int.Parse(Location_List.SelectedValue), Narration_TXT.Text);if (ReturnValue == 1){
Operation_Link.Attributes.Add("OnClick","showDialog('COMPANY_CONTROL')"); ---> javascript function}
}
}
please mark as answer if this is the solution
rohit gandhi
Use RegisterClientScriptBlock to add the javascript after gettgin success ful insert.
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "Successs", "Test();", true);
Imran
[MCTS]
Few have audacity to speak truth
http://knowledgebaseworld.blogspot.com/
its not working.
i used this
Operation_Link.Attributes.Add("OnClick","showDialog('COMPANY_CONTROL')");
this woking but second time. so give me an idea how to display first time. when i click again on linkbutton then it display. not first time after inserting.
please mark as answer if this is the solution
rohit gandhi
Its working perfectly my dear friend
Linkbutton
<asp:LinkButton ID="Operation_Link" Text="Text" runat="server" OnClick="Operation_Link_Click">asp:LinkButton>
Serverside code
protected void Operation_Link_Click(object sender, EventArgs e){
if(your condition = true)
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "Successs", "Test();", true);}
Javascript:
function Test(){
alert('hi');}
I am getting hi after clicking on linkbutton
you just have to add
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "Successs", "showDialog('COMPANY_CONTROL');", true);
or put alert into your function showDialog to sure that its reaches to that function
Imran
[MCTS]
Few have audacity to speak truth
http://knowledgebaseworld.blogspot.com/
hi Rohit_a_g,
from ur post i got that your code is working on second click of that link button so do one change only in your code :Instead of adding attributes just use onClientclick properties in your link button tag and call that function.Here is an example:--->
<asp:LinkButton ID="Operation_Link" runat="server" OnClick="Operation_Link_Click" OnClientClick="showDialog('COMPANY_CONTROL');">asp:LinkButton>
There is another solution :--Add this line in your page_load event instead of Operation_Link_Click event
Operation_Link.Attributes.Add("OnClick","showDialog('COMPANY_CONTROL');");
if any queries then ask....
Please remember to click Mark as Answer on the post that helps you. This can be beneficial
to other community members reading the thread.
Hi gopsy_25,
Your suggession is not right, its not fits to this context at all; with your code its first time only it will make call to the javascript function, which he dont need I think.
Imran
[MCTS]
Few have audacity to speak truth
http://knowledgebaseworld.blogspot.com/
sorry to say but its not working. it reaches to my function but its not working. don't say my function is wrong because its working second time. using my function
Operation_Link.Attributes.Add("OnClick","showDialog('COMPANY_CONTROL')");
give me any other idea that its working for first time also.
please mark as answer if this is the solution
rohit gandhi
you can write the code in javascript by check the return value , i believe that you can solve the problem
Tracy.Bai
any questions can contact with me
if you use registerclientscript blcok at that time it reaches to the function right? that means its working, the problem may be in the function, can you write your function here?
Imran
[MCTS]
Few have audacity to speak truth
http://knowledgebaseworld.blogspot.com/