(Return values of onclientclick and onclick new pages) (obtain the control value in the gridview)

Source: Internet
Author: User

Once encountered such a problem
In a pop-up window
One of my buttons needs to execute two events.
I,
Protected void button#click (Object sender, eventargs E)
{
String revengeboy = "";
Revengeboy = "I'm a killer, marathon, killing and killing every day"; // This is just an example.
}
II,
Then you have to execute this event.
<Script language = "JavaScript" type = "text/JavaScript">
// <! CDATA [

Function inputbutton1_onclick ()
{
Window. dialogarguments. aspnetform. inputroles. value = '<% = revengeboy %>'; // return the value
Window. Close (); // close the window
}
//]>
</SCRIPT>

It is depressing that onclientclick is executed first than onclick. To achieve the method onclientclick = "inputbutton#onclick ()" onclick = button#click in the execution script, this is totally ineffective.
And I think that
Protected void button#click (Object sender, eventargs E)
{
Getselectedroles ();
This. button1.attributes. Add ("onclick", "javascript: inputbutton1_onclick ()");
}
In this way, the effect can be achieved, but it is not very outrageous if I make a mistake. How can this problem be achieved only by pressing the button twice;

Final method:
However, after having gone through these several mistakes, I think it is only possible to write him to the background page...
Protected void button#click (Object sender, eventargs E)
{
Getselectedroles ();
Response. Write ("<SCRIPT> window. dialogarguments. aspnetform. inputroles. value = '" + revengeboy + "'; window. Close (); </SCRIPT> ");
} Well, this has achieved what I want. Haha !!!

Private void getselectedroles () // find the control from the gridview and obtain the value
{
Foreach (gridviewrow row in gridview1.rows)
{

// This. lable3.text + = + (row. findcontrol ("label2") as label). text;
// Itemname = itemname + (Label) gridview1.rows [row. rowindex]. findcontrol ("label2 ")). text ;//. cells [4]. controls [0]). text. trim ();
Roles = (Label) gridview1.rows [row. rowindex]. cells [1]. findcontrol ("txtrolename"). Text. tostring ();
Checkbox CB1 = (checkbox) gridview1.rows [row. rowindex]. findcontrol ("checkbox4 ");
Checkbox CB2 = (checkbox) gridview1.rows [row. rowindex]. findcontrol ("checkbox5 ");
Checkbox CB3 = (checkbox) gridview1.rows [row. rowindex]. findcontrol ("checkbox6 ");
If (cb1.checked = true | cb2.checked = true | cb3.checked = true)
{
If (cb1.checked = true)
{
Read = "R-Y ";
}
Else
{
Read = "R-N ";
}
If (cb2.checked = true)
{
Write = "W-Y ";
}
Else
{
Write = "W-N ";
}
If (cb3.checked = true)
{
Update = "U-Y ";
}
Else
{
Update = "U-N ";
}
Itemname = itemname + roles + "," + read + "," + write + "," + update + "| ";
}

}
This. label3.text = itemname. tostring ();
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.