0
votes

I have a static method where I want to get the "div" inner html I Used the following method

[WebMethod]
    public static string SetFileNameU(List<string> someValues)
    {
    string linkmain =   link.Replace("Journey=R", "Journey="+journey);

     SearcResult src = new SearcResult();
     src.iframesourceType(linkmain);
 return linkmain;

    }

and here i called non static function passing link to that fucntion

  public void iframesourceType(string linksrc) 
    {
        frame.InnerHtml = ""; //// error frame is null

    }

and returns the error

object refrence not set to initialization of object

my html frame is div

     <div runat="server" id= "frame"  class="col-md-9">
               <%--<iframe class="ifr" >

                </iframe>--%>
            </div>

kindly tell me how to change content my webform class is searchresult.cs and frame.innerHtml was working at form laod and can be aceesed but calling from static after ajax call in non static function it works

why static?

1-first time when i open file i use that

      protected void Page_Load(object sender, EventArgs e)
    {

            string link = Convert.ToString(Session["url"]);
            Label1.Text = link;
            SomewhereInTheCode();
            frame.InnerHtml = (" <iframe class='ifr' frameborder='0'  src='" + link + "' > </iframe>");

    }

now i am using ajax call to web method to change inner HTML as needed see the code at top and it work only at page load

div is runat server so acesed from server side as frame

1
You already wrote the problem in the comments error frame is null - Guy
actually frame is a div i am posting html too see - GLOBAL TECH
so it wil never be null - GLOBAL TECH
@Guy you peoples are officialy guys nnobody at rescue - GLOBAL TECH
Why did you mark your method as a WebMethod? And why does it need to be static instead of an instance method? - mason

1 Answers

0
votes

You Cannot access any of the form elements in a static method. Only instanciable methods can access it.

If you want to change the content of div through web method just return the content and then assign the HTML to div in the success function of Ajax Call.

Ajax Function

  $.ajax({
     url     : "FileName.aspx/SetFileNameU",
     method  : "GET"/"POST",
     data    : "{someValues:['value1','value2','value3']}",
     success : function (data) {
        $('#frame').html(data);
     } 
  });