ASP (C #) Treeview frontend background jump Association, TMD, finally got it out

Source: Internet
Author: User

I spent several days with my classmates and finally handled the problem. I thought it was solved yesterday, but I found the vulnerability again when I used it today, it took a long time at noon and afternoon to find out. Thank you, little sweat ......

Objective: To capture the selected content in the tree menu on the left-side frame page, load the corresponding page to a specified frame for display, and pass the selected content ......

Method 1: (yesterday's method later proved that this method has a vulnerability)

<! -- This code can capture the selected text in the checkedbox of the Treeview control on the page. However, the tragedy is that when the checkbox on the Treeview is selected and then folded, he will be stunned, no text found-begin->

<SCRIPT type = "text/JavaScript">
Function check (){
VaR html = "";
VaR check = Document. getelementbyid ("treeview1"). getelementsbytagname ("input ");
For (VAR I = 0; I <check. length; I ++ ){
If (check [I]. Checked)
HTML + = check [I]. Title + "";

}
// Window. Top. Frames ["Left" mirror.doc ument. getelementbyid ("text1"). value = HTML;
// Parent. Frames ("right"). Frames ("mainframe"). Location. href = "mainwindow. aspx? Hrz_heng = "+" <% = session ["request"] %> ";
Parent. Frames ("right"). Frames ("mainframe"). Location. href = "mainwindow. aspx? Hrz_heng = "+ HTML;
}

</SCRIPT>

<! ------------------------------------------------------ End users>

Method 2:

<! --------- This code is triggered by clicking the check box. If the object type is checkbox and the Object Name is input, it is forced to run ------- begin ------> in the background.

<Script language = "JavaScript" type = "text/JavaScript">
// Trigger the event when you click the check box
Function postbackbyobject ()
{
VaR o = Window. event. srcelement;
If (O. tagname = "input" & O. type = "checkbox ")
{
_ Dopostback ("","");
}
}
</SCRIPT>

<! ------------------------------------------------------------------- End ---------------------------------------------->

The Treeview control in ASP:

<Begin <<

<Asp: Treeview id = "treeview1" runat = "server"
Imageset = "xpfileexplorer" enableclientscript = "false"
Width = "250px" showcheckboxes = "leaf" font-size = "medium"

Showlines = "true" autogeneratedatabindings = "true"
Ontreenodecheckchanged = "treeviewappstreenodecheckchanged">
<Selectednodestyle font-overline = "false" backcolor = "burlywood" font-bold = "true"/>
</ASP: Treeview>

<End, <<

........................................ .............. The above is the front-end code ........................

............. Background code ............................

Add the onclick attribute to the properties of the Treeview control:

Treeview1.attributes. Add ("onclick", "postbackbyobject ()");

<! ------------------------------------- The code is executed forcibly from the foreground --------------------------------------------------------->

Protected void treeviewinclutreenodecheckchanged (Object sender, treenodeeventargs E)
{

String A = "";
If (session ["request"]! = NULL)
{
A = session ["request"]. tostring ();
}
// Select
If (E. node. Checked = true)
{
A + = E. node. Text + ",";
}
// Cancel
If (E. node. Checked = false)
{
A = A. Replace (E. node. Text + ",","");
}
Session ["request"] =;
// Response. Write ("<SCRIPT> parent. Frames ('right'). Frames ('mainframework'). Location. href = 'mainwindow. aspx? Hrz_heng = '+' <% = session ['request'] %> '; </SCRIPT> ");
// Response. write ("<SCRIPT> parent. frames ('right '). frames ('mainframework '). location. href = 'shit. aspx '; </SCRIPT> ");

}

<--------------------------------------- End certificate>

Comments: This method is very good and can achieve the effect, but the disadvantage is that the checkbox at each point always refreshes the page once, and the page interacts with the background. The Flash is so powerful that it is not beautiful, therefore, we reject it ......

........................................ .............

Method 3:

Foreground: Use a linkbutton Control

<Asp: linkbutton id = "linkbutton1" runat = "server" onclick = "linkbutton1_click"> linkbutton </ASP: linkbutton>

Background:

Protected void linkbutton#click (Object sender, eventargs E)
{
String S = "";
For (INT I = 0; I <= treeview1.checkednodes. Count-1; I ++)
{
S = S + treeview1.checkednodes [I]. Text. tostring (). Trim () + ",";
}
S = S. Remove (S. Length-1 );

Response. Write ("<SCRIPT> parent. Frames ('right'). Frames ('mainframework'). Location. href = 'mainwindow. aspx? Hrz_heng = "+ S +" '; </SCRIPT> ");
}

The most critical code is the last sentence:

Response. Write ("<SCRIPT> parent. Frames ('right'). Frames ('mainframework'). Location. href = 'mainwindow. aspx? Hrz_heng = "+ S +" '; </SCRIPT> ");

Grandma's, after so long, the last simple method can solve the problem ......

 

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.